Skip to content

Commit

Permalink
Deprecate Expr::column_refs
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Jun 24, 2024
1 parent 459afbb commit 402c3db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
1 change: 1 addition & 0 deletions datafusion/expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,7 @@ impl Expr {
}

/// Return all referenced columns of this expression.
#[deprecated(since = "40.0.0", note = "use Expr::column_refs instead")]
pub fn to_columns(&self) -> Result<HashSet<Column>> {
let mut using_columns = HashSet::new();
expr_to_columns(self, &mut using_columns)?;
Expand Down
9 changes: 6 additions & 3 deletions datafusion/expr/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ use crate::logical_plan::{
use crate::type_coercion::binary::{comparison_coercion, values_coercion};
use crate::utils::{
can_hash, columnize_expr, compare_sort_expr, expand_qualified_wildcard,
expand_wildcard, find_valid_equijoin_key_pair, group_window_expr_by_sort_keys,
expand_wildcard, expr_to_columns, find_valid_equijoin_key_pair,
group_window_expr_by_sort_keys,
};
use crate::{
and, binary_expr, logical_plan::tree_node::unwrap_arc, DmlStatement, Expr,
Expand Down Expand Up @@ -1070,14 +1071,16 @@ impl LogicalPlanBuilder {
let left_key = l.into();
let right_key = r.into();

let left_using_columns = left_key.to_columns()?;
let mut left_using_columns = HashSet::new();
expr_to_columns(&left_key, &mut left_using_columns)?;
let normalized_left_key = normalize_col_with_schemas_and_ambiguity_check(
left_key,
&[&[self.plan.schema(), right.schema()]],
&[left_using_columns],
)?;

let right_using_columns = right_key.to_columns()?;
let mut right_using_columns = HashSet::new();
expr_to_columns(&right_key, &mut right_using_columns)?;
let normalized_right_key = normalize_col_with_schemas_and_ambiguity_check(
right_key,
&[&[self.plan.schema(), right.schema()]],
Expand Down
18 changes: 1 addition & 17 deletions datafusion/expr/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ mod tests {
use super::*;
use crate::{
col, cube, expr, expr_vec_fmt, grouping_set, lit, rollup,
test::function_stub::sum_udaf, AggregateFunction, Cast, WindowFrame,
test::function_stub::sum_udaf, AggregateFunction, WindowFrame,
WindowFunctionDefinition,
};

Expand Down Expand Up @@ -1698,20 +1698,4 @@ mod tests {
let expr = col("a").eq(lit(5)).or(col("b"));
assert_eq!(split_conjunction_owned(expr.clone()), vec![expr]);
}

#[test]
fn test_collect_expr() -> Result<()> {
let mut accum: HashSet<Column> = HashSet::new();
expr_to_columns(
&Expr::Cast(Cast::new(Box::new(col("a")), DataType::Float64)),
&mut accum,
)?;
expr_to_columns(
&Expr::Cast(Cast::new(Box::new(col("a")), DataType::Float64)),
&mut accum,
)?;
assert_eq!(1, accum.len());
assert!(accum.contains(&Column::from_name("a")));
Ok(())
}
}

0 comments on commit 402c3db

Please sign in to comment.