Skip to content

Commit ac3a68e

Browse files
authored
Add Expr::Alias passthrough to Expr::placement() (#20237)
Pulling out of #20117. Aliases cause no compute or changes to how compute happens. They should delegate to their inner expression.
1 parent dc0c21b commit ac3a68e

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

datafusion/expr/src/expr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,7 @@ impl Expr {
15461546
match self {
15471547
Expr::Column(_) => ExpressionPlacement::Column,
15481548
Expr::Literal(_, _) => ExpressionPlacement::Literal,
1549+
Expr::Alias(inner) => inner.expr.placement(),
15491550
Expr::ScalarFunction(func) => {
15501551
let arg_placements: Vec<_> =
15511552
func.args.iter().map(|arg| arg.placement()).collect();

datafusion/sqllogictest/test_files/projection_pushdown.slt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,8 @@ EXPLAIN SELECT id, s['value'], s['value'] + 10, s['label'] FROM simple_struct OR
856856
----
857857
logical_plan
858858
01)Sort: simple_struct.id ASC NULLS LAST, fetch=3
859-
02)--Projection: simple_struct.id, __common_expr_1 AS simple_struct.s[value], __common_expr_1 AS simple_struct.s[value] + Int64(10), get_field(simple_struct.s, Utf8("label"))
860-
03)----Projection: get_field(simple_struct.s, Utf8("value")) AS __common_expr_1, simple_struct.id, simple_struct.s
861-
04)------TableScan: simple_struct projection=[id, s]
859+
02)--Projection: simple_struct.id, get_field(simple_struct.s, Utf8("value")) AS simple_struct.s[value], get_field(simple_struct.s, Utf8("value")) + Int64(10), get_field(simple_struct.s, Utf8("label"))
860+
03)----TableScan: simple_struct projection=[id, s]
862861
physical_plan
863862
01)SortExec: TopK(fetch=3), expr=[id@0 ASC NULLS LAST], preserve_partitioning=[false]
864863
02)--DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/projection_pushdown/simple.parquet]]}, projection=[id, get_field(s@1, value) as simple_struct.s[value], get_field(s@1, value) + 10 as simple_struct.s[value] + Int64(10), get_field(s@1, label) as simple_struct.s[label]], file_type=parquet, predicate=DynamicFilter [ empty ]
@@ -969,10 +968,9 @@ query TT
969968
EXPLAIN SELECT s['value'] + s['value'] as doubled FROM simple_struct WHERE id > 2;
970969
----
971970
logical_plan
972-
01)Projection: __common_expr_1 + __common_expr_1 AS doubled
973-
02)--Projection: get_field(simple_struct.s, Utf8("value")) AS __common_expr_1
974-
03)----Filter: simple_struct.id > Int64(2)
975-
04)------TableScan: simple_struct projection=[id, s], partial_filters=[simple_struct.id > Int64(2)]
971+
01)Projection: get_field(simple_struct.s, Utf8("value")) + get_field(simple_struct.s, Utf8("value")) AS doubled
972+
02)--Filter: simple_struct.id > Int64(2)
973+
03)----TableScan: simple_struct projection=[id, s], partial_filters=[simple_struct.id > Int64(2)]
976974
physical_plan
977975
01)ProjectionExec: expr=[get_field(s@0, value) + get_field(s@0, value) as doubled]
978976
02)--FilterExec: id@0 > 2, projection=[s@1]

0 commit comments

Comments
 (0)