This is an automated email from the ASF dual-hosted git repository.
jonah pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 465d6609bc Do no alias in TableScan filters (#13048)
465d6609bc is described below
commit 465d6609bc7c284321ac7b1c2934a0a21951346f
Author: Emil Ejbyfeldt <[email protected]>
AuthorDate: Tue Oct 22 05:11:49 2024 +0200
Do no alias in TableScan filters (#13048)
---
datafusion/core/tests/expr_api/simplification.rs | 4 ++--
datafusion/expr/src/expr_rewriter/mod.rs | 9 ++++++---
datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs | 2 +-
datafusion/sqllogictest/test_files/tpch/q22.slt.part | 2 +-
4 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/datafusion/core/tests/expr_api/simplification.rs
b/datafusion/core/tests/expr_api/simplification.rs
index 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.rs
index 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 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(_)
+ ),
}
}
diff --git a/datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs
b/datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs
index 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.part
index 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_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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]