Skip to content

Commit

Permalink
Do no alias in TableScan filters (apache#13048)
Browse files Browse the repository at this point in the history
  • Loading branch information
eejbyfeldt authored Oct 22, 2024
1 parent b978cf8 commit 465d660
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions datafusion/core/tests/expr_api/simplification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ fn simplify_scan_predicate() -> Result<()> {
.build()?;

// before simplify: t.g = power(t.f, 1.0)
// after simplify: (t.g = t.f) as "t.g = power(t.f, 1.0)"
let expected = "TableScan: test, full_filters=[g = f AS g = power(f,Float64(1))]";
// after simplify: t.g = t.f"
let expected = "TableScan: test, full_filters=[g = f]";
let actual = get_optimized_plan_formatted(plan, &Utc::now());
assert_eq!(expected, actual);
Ok(())
Expand Down
9 changes: 6 additions & 3 deletions datafusion/expr/src/expr_rewriter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,12 @@ impl NamePreserver {
/// Create a new NamePreserver for rewriting the `expr` that is part of the specified plan
pub fn new(plan: &LogicalPlan) -> Self {
Self {
// The schema of Filter and Join nodes comes from their inputs rather than their output expressions,
// so there is no need to use aliases to preserve expression names.
use_alias: !matches!(plan, LogicalPlan::Filter(_) | LogicalPlan::Join(_)),
// The schema of Filter, Join and TableScan nodes comes from their inputs rather than
// their expressions, so there is no need to use aliases to preserve expression names.
use_alias: !matches!(
plan,
LogicalPlan::Filter(_) | LogicalPlan::Join(_) | LogicalPlan::TableScan(_)
),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ mod tests {
assert_eq!(1, table_scan.schema().fields().len());
assert_fields_eq(&table_scan, vec!["a"]);

let expected = "TableScan: test projection=[a], full_filters=[Boolean(true) AS b IS NOT NULL]";
let expected = "TableScan: test projection=[a], full_filters=[Boolean(true)]";

assert_optimized_plan_eq(table_scan, expected)
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/sqllogictest/test_files/tpch/q22.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ logical_plan
14)--------------Aggregate: groupBy=[[]], aggr=[[avg(customer.c_acctbal)]]
15)----------------Projection: customer.c_acctbal
16)------------------Filter: customer.c_acctbal > Decimal128(Some(0),15,2) AND substr(customer.c_phone, Int64(1), Int64(2)) IN ([Utf8("13"), Utf8("31"), Utf8("23"), Utf8("29"), Utf8("30"), Utf8("18"), Utf8("17")])
17)--------------------TableScan: customer projection=[c_phone, c_acctbal], partial_filters=[customer.c_acctbal > Decimal128(Some(0),15,2) AS customer.c_acctbal > Decimal128(Some(0),30,15), substr(customer.c_phone, Int64(1), Int64(2)) IN ([Utf8("13"), Utf8("31"), Utf8("23"), Utf8("29"), Utf8("30"), Utf8("18"), Utf8("17")]), customer.c_acctbal > Decimal128(Some(0),15,2)]
17)--------------------TableScan: customer projection=[c_phone, c_acctbal], partial_filters=[customer.c_acctbal > Decimal128(Some(0),15,2), substr(customer.c_phone, Int64(1), Int64(2)) IN ([Utf8("13"), Utf8("31"), Utf8("23"), Utf8("29"), Utf8("30"), Utf8("18"), Utf8("17")])]
physical_plan
01)SortPreservingMergeExec: [cntrycode@0 ASC NULLS LAST]
02)--SortExec: expr=[cntrycode@0 ASC NULLS LAST], preserve_partitioning=[true]
Expand Down

0 comments on commit 465d660

Please sign in to comment.