Skip to content

Commit 4e0bc18

Browse files
authored
Revert "fix: Ensure column names do not change with expand_views_at_output (apache#19019)" (#73)
This reverts commit 2626fc2.
1 parent 74ea766 commit 4e0bc18

File tree

4 files changed

+33
-77
lines changed

4 files changed

+33
-77
lines changed

datafusion/expr/src/expr_rewriter/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,7 @@ fn coerce_exprs_for_schema(
260260
}
261261
#[expect(deprecated)]
262262
Expr::Wildcard { .. } => Ok(expr),
263-
_ => {
264-
// maintain the original name when casting
265-
let name = dst_schema.field(idx).name();
266-
Ok(expr.cast_to(new_type, src_schema)?.alias(name))
267-
}
263+
_ => expr.cast_to(new_type, src_schema),
268264
}
269265
} else {
270266
Ok(expr)

datafusion/optimizer/src/analyzer/type_coercion.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ mod test {
14411441
true,
14421442
plan.clone(),
14431443
@r"
1444-
Projection: CAST(a AS LargeUtf8) AS a
1444+
Projection: CAST(a AS LargeUtf8)
14451445
EmptyRelation: rows=0
14461446
"
14471447
)?;
@@ -1477,7 +1477,7 @@ mod test {
14771477
true,
14781478
plan.clone(),
14791479
@r"
1480-
Projection: CAST(a AS LargeUtf8) AS a
1480+
Projection: CAST(a AS LargeUtf8)
14811481
EmptyRelation: rows=0
14821482
"
14831483
)?;
@@ -1507,7 +1507,7 @@ mod test {
15071507
true,
15081508
sort_plan.clone(),
15091509
@r"
1510-
Projection: CAST(a AS LargeUtf8) AS a
1510+
Projection: CAST(a AS LargeUtf8)
15111511
Sort: a ASC NULLS FIRST
15121512
Projection: a
15131513
EmptyRelation: rows=0
@@ -1536,7 +1536,7 @@ mod test {
15361536
true,
15371537
plan.clone(),
15381538
@r"
1539-
Projection: CAST(a AS LargeUtf8) AS a
1539+
Projection: CAST(a AS LargeUtf8)
15401540
Sort: a ASC NULLS FIRST
15411541
Projection: a
15421542
EmptyRelation: rows=0
@@ -1572,7 +1572,7 @@ mod test {
15721572
true,
15731573
plan.clone(),
15741574
@r"
1575-
Projection: CAST(a AS LargeBinary) AS a
1575+
Projection: CAST(a AS LargeBinary)
15761576
EmptyRelation: rows=0
15771577
"
15781578
)?;
@@ -1629,7 +1629,7 @@ mod test {
16291629
true,
16301630
sort_plan.clone(),
16311631
@r"
1632-
Projection: CAST(a AS LargeBinary) AS a
1632+
Projection: CAST(a AS LargeBinary)
16331633
Sort: a ASC NULLS FIRST
16341634
Projection: a
16351635
EmptyRelation: rows=0
@@ -1660,7 +1660,7 @@ mod test {
16601660
true,
16611661
plan.clone(),
16621662
@r"
1663-
Projection: CAST(a AS LargeBinary) AS a
1663+
Projection: CAST(a AS LargeBinary)
16641664
Sort: a ASC NULLS FIRST
16651665
Projection: a
16661666
EmptyRelation: rows=0

datafusion/optimizer/tests/optimizer_integration.rs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -538,15 +538,14 @@ fn recursive_cte_projection_pushdown() -> Result<()> {
538538
// columns from the base table and recursive table, eliminating unused columns
539539
assert_snapshot!(
540540
format!("{plan}"),
541-
@r"
542-
SubqueryAlias: nodes
543-
RecursiveQuery: is_distinct=false
544-
Projection: test.col_int32 AS id
545-
TableScan: test projection=[col_int32]
546-
Projection: CAST(CAST(nodes.id AS Int64) + Int64(1) AS Int32) AS id
547-
Filter: nodes.id < Int32(3)
548-
TableScan: nodes projection=[id]
549-
"
541+
@r#"SubqueryAlias: nodes
542+
RecursiveQuery: is_distinct=false
543+
Projection: test.col_int32 AS id
544+
TableScan: test projection=[col_int32]
545+
Projection: CAST(CAST(nodes.id AS Int64) + Int64(1) AS Int32)
546+
Filter: nodes.id < Int32(3)
547+
TableScan: nodes projection=[id]
548+
"#
550549
);
551550
Ok(())
552551
}
@@ -562,16 +561,14 @@ fn recursive_cte_with_aliased_self_reference() -> Result<()> {
562561

563562
assert_snapshot!(
564563
format!("{plan}"),
565-
@r"
566-
SubqueryAlias: nodes
567-
RecursiveQuery: is_distinct=false
568-
Projection: test.col_int32 AS id
569-
TableScan: test projection=[col_int32]
570-
Projection: CAST(CAST(child.id AS Int64) + Int64(1) AS Int32) AS id
571-
SubqueryAlias: child
572-
Filter: nodes.id < Int32(3)
573-
TableScan: nodes projection=[id]
574-
",
564+
@r#"SubqueryAlias: nodes
565+
RecursiveQuery: is_distinct=false
566+
Projection: test.col_int32 AS id
567+
TableScan: test projection=[col_int32]
568+
Projection: CAST(CAST(child.id AS Int64) + Int64(1) AS Int32)
569+
SubqueryAlias: child
570+
Filter: nodes.id < Int32(3)
571+
TableScan: nodes projection=[id]"#,
575572
);
576573
Ok(())
577574
}
@@ -624,16 +621,15 @@ fn recursive_cte_projection_pushdown_baseline() -> Result<()> {
624621
// and only the needed column is selected from the recursive table
625622
assert_snapshot!(
626623
format!("{plan}"),
627-
@r"
628-
SubqueryAlias: countdown
629-
RecursiveQuery: is_distinct=false
630-
Projection: test.col_int32 AS n
631-
Filter: test.col_int32 = Int32(5)
632-
TableScan: test projection=[col_int32]
633-
Projection: CAST(CAST(countdown.n AS Int64) - Int64(1) AS Int32) AS n
634-
Filter: countdown.n > Int32(1)
635-
TableScan: countdown projection=[n]
636-
"
624+
@r#"SubqueryAlias: countdown
625+
RecursiveQuery: is_distinct=false
626+
Projection: test.col_int32 AS n
627+
Filter: test.col_int32 = Int32(5)
628+
TableScan: test projection=[col_int32]
629+
Projection: CAST(CAST(countdown.n AS Int64) - Int64(1) AS Int32)
630+
Filter: countdown.n > Int32(1)
631+
TableScan: countdown projection=[n]
632+
"#
637633
);
638634
Ok(())
639635
}

datafusion/sqllogictest/test_files/cast.slt

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -89,39 +89,3 @@ select * from t0 where v0<1e100;
8989

9090
statement ok
9191
drop table t0;
92-
93-
94-
# ensure that automatically casting with "datafusion.optimizer.expand_views_at_output" does not
95-
# change the column name
96-
97-
statement ok
98-
create table t(a int, b varchar);
99-
100-
statement ok
101-
set datafusion.optimizer.expand_views_at_output = true;
102-
103-
query TT
104-
explain select * from t;
105-
----
106-
logical_plan
107-
01)Projection: t.a, CAST(t.b AS LargeUtf8) AS b
108-
02)--TableScan: t projection=[a, b]
109-
physical_plan
110-
01)ProjectionExec: expr=[a@0 as a, CAST(b@1 AS LargeUtf8) as b]
111-
02)--DataSourceExec: partitions=1, partition_sizes=[0]
112-
113-
query TT
114-
explain select b from t;
115-
----
116-
logical_plan
117-
01)Projection: CAST(t.b AS LargeUtf8) AS b
118-
02)--TableScan: t projection=[b]
119-
physical_plan
120-
01)ProjectionExec: expr=[CAST(b@0 AS LargeUtf8) as b]
121-
02)--DataSourceExec: partitions=1, partition_sizes=[0]
122-
123-
statement ok
124-
set datafusion.optimizer.expand_views_at_output = false;
125-
126-
statement ok
127-
drop table t;

0 commit comments

Comments
 (0)