Apache DataFusion SQL Query Engine
Do no alias in TableScan filters (#13048)
Emil Ejbyfeldt465d6609bc7c
diff --git a/datafusion/core/tests/expr_api/simplification.rs b/datafusion/core/tests/expr_api/simplification.rsindex d7995d4663..800a087587 100644--- a/datafusion/core/tests/expr_api/simplification.rs+++ b/datafusion/core/tests/expr_api/simplification.rs@@ -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(())diff --git a/datafusion/expr/src/expr_rewriter/mod.rs b/datafusion/expr/src/expr_rewriter/mod.rsindex 15930914dd..47cc947be3 100644--- a/datafusion/expr/src/expr_rewriter/mod.rs+++ b/datafusion/expr/src/expr_rewriter/mod.rs@@ -306,9 +306,12 @@ impl NamePreserver {/// Create a new NamePreserver for rewriting the `expr` that is part of the specified planpub 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(_)+ ),}}diff --git a/datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs b/datafusion/optimizer/src/simplify_expressions/simplify_exprs.rsindex c0142ae0fc..200f1f159d 100644--- a/datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs+++ b/datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs@@ -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)}diff --git a/datafusion/sqllogictest/test_files/tpch/q22.slt.part b/datafusion/sqllogictest/test_files/tpch/q22.slt.partindex d2168b0136..2955748160 100644--- a/datafusion/sqllogictest/test_files/tpch/q22.slt.part+++ b/datafusion/sqllogictest/test_files/tpch/q22.slt.part@@ -72,7 +72,7 @@ logical_plan14)--------------Aggregate: groupBy=[[]], aggr=[[avg(customer.c_acctbal)]]15)----------------Projection: customer.c_acctbal16)------------------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_plan01)SortPreservingMergeExec: [cntrycode@0 ASC NULLS LAST]02)--SortExec: expr=[cntrycode@0 ASC NULLS LAST], preserve_partitioning=[true]