-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add Expr::column_refs to find column references without copying #10948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0bf8ccb
09dba99
cefb7bd
6857618
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,7 @@ pub const COUNT_STAR_EXPANSION: ScalarValue = ScalarValue::Int64(Some(1)); | |
|
|
||
| /// Recursively walk a list of expression trees, collecting the unique set of columns | ||
| /// referenced in the expression | ||
| #[deprecated(since = "40.0.0", note = "Expr::add_column_refs instead")] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function is not used anywhere in the datafusion codebase |
||
| pub fn exprlist_to_columns(expr: &[Expr], accum: &mut HashSet<Column>) -> Result<()> { | ||
| for e in expr { | ||
| expr_to_columns(e, accum)?; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -561,12 +561,9 @@ fn infer_join_predicates( | |
| .filter_map(|predicate| { | ||
| let mut join_cols_to_replace = HashMap::new(); | ||
|
|
||
| let columns = match predicate.to_columns() { | ||
| Ok(columns) => columns, | ||
| Err(e) => return Some(Err(e)), | ||
| }; | ||
| let columns = predicate.column_refs(); | ||
|
|
||
| for col in columns.iter() { | ||
| for &col in columns.iter() { | ||
| for (l, r) in join_col_keys.iter() { | ||
| if col == *l { | ||
| join_cols_to_replace.insert(col, *r); | ||
|
|
@@ -798,7 +795,7 @@ impl OptimizerRule for PushDownFilter { | |
| let mut keep_predicates = vec![]; | ||
| let mut push_predicates = vec![]; | ||
| for expr in predicates { | ||
| let cols = expr.to_columns()?; | ||
| let cols = expr.column_refs(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a pretty good example where there is no need to copy |
||
| if cols.iter().all(|c| group_expr_columns.contains(c)) { | ||
| push_predicates.push(expr); | ||
| } else { | ||
|
|
@@ -899,7 +896,7 @@ impl OptimizerRule for PushDownFilter { | |
| let predicate_push_or_keep = split_conjunction(&filter.predicate) | ||
| .iter() | ||
| .map(|expr| { | ||
| let cols = expr.to_columns()?; | ||
| let cols = expr.column_refs(); | ||
| if cols.iter().any(|c| prevent_cols.contains(&c.name)) { | ||
| Ok(false) // No push (keep) | ||
| } else { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of this function is quite nice now compared to the
expr_to_columnsone: https://github.com/alamb/datafusion/blob/58d0c34d77c9a5202e62b9281cdbf1046abaa096/datafusion/expr/src/utils.rs#L264-L309