alamb commented on code in PR #10948:
URL: https://github.com/apache/datafusion/pull/10948#discussion_r1642553216
##########
datafusion/optimizer/src/push_down_filter.rs:
##########
@@ -785,7 +782,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();
Review Comment:
This is a pretty good example where there is no need to copy `Column`s
simply to check if they are referenced.
##########
datafusion/expr/src/expr.rs:
##########
@@ -1333,6 +1335,46 @@ impl Expr {
Ok(using_columns)
}
+ /// Return all references to columns in this expression.
+ ///
+ /// # Example
+ /// ```
+ /// # use std::collections::HashSet;
+ /// # use datafusion_common::Column;
+ /// # use datafusion_expr::col;
+ /// // For an expression `a + (b * a)`
+ /// let expr = col("a") + (col("b") * col("a"));
+ /// let refs = expr.column_refs();
+ /// // refs contains "a" and "b"
+ /// assert_eq!(refs.len(), 2);
+ /// assert!(refs.contains(&Column::new_unqualified("a")));
+ /// assert!(refs.contains(&Column::new_unqualified("b")));
+ /// ```
+ pub fn column_refs(&self) -> HashSet<&Column> {
Review Comment:
The implementation of this function is quite nice now compared to the
`expr_to_columns` one:
https://github.com/alamb/datafusion/blob/58d0c34d77c9a5202e62b9281cdbf1046abaa096/datafusion/expr/src/utils.rs#L264-L309
##########
datafusion/expr/src/utils.rs:
##########
@@ -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")]
Review Comment:
this function is not used anywhere in the datafusion codebase
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]