Skip to content

Commit d91ce06

Browse files
authored
fix: shouldn't pass alias through into subquery. (#4141)
1 parent 9de893e commit d91ce06

File tree

9 files changed

+37
-37
lines changed

9 files changed

+37
-37
lines changed

benchmarks/expected-plans/q13.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ Sort: custdist DESC NULLS FIRST, c_orders.c_count DESC NULLS FIRST
22
Projection: c_orders.c_count, COUNT(UInt8(1)) AS custdist
33
Aggregate: groupBy=[[c_orders.c_count]], aggr=[[COUNT(UInt8(1))]]
44
Projection: c_orders.COUNT(orders.o_orderkey) AS c_count, alias=c_orders
5-
Projection: c_orders.COUNT(orders.o_orderkey), alias=c_orders
6-
Projection: COUNT(orders.o_orderkey), alias=c_orders
5+
Projection: COUNT(orders.o_orderkey), alias=c_orders
6+
Projection: COUNT(orders.o_orderkey)
77
Aggregate: groupBy=[[customer.c_custkey]], aggr=[[COUNT(orders.o_orderkey)]]
88
Left Join: customer.c_custkey = orders.o_custkey
99
TableScan: customer projection=[c_custkey]

benchmarks/expected-plans/q22.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Sort: custsale.cntrycode ASC NULLS LAST
22
Projection: custsale.cntrycode, COUNT(UInt8(1)) AS numcust, SUM(custsale.c_acctbal) AS totacctbal
33
Aggregate: groupBy=[[custsale.cntrycode]], aggr=[[COUNT(UInt8(1)), SUM(custsale.c_acctbal)]]
4-
Projection: custsale.cntrycode, custsale.c_acctbal, alias=custsale
5-
Projection: substr(customer.c_phone, Int64(1), Int64(2)) AS cntrycode, customer.c_acctbal, alias=custsale
4+
Projection: cntrycode, customer.c_acctbal, alias=custsale
5+
Projection: substr(customer.c_phone, Int64(1), Int64(2)) AS cntrycode, customer.c_acctbal
66
Filter: CAST(customer.c_acctbal AS Decimal128(19, 6)) > __sq_1.__value
77
CrossJoin:
88
LeftAnti Join: customer.c_custkey = orders.o_custkey

benchmarks/expected-plans/q7.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Sort: shipping.supp_nation ASC NULLS LAST, shipping.cust_nation ASC NULLS LAST, shipping.l_year ASC NULLS LAST
22
Projection: shipping.supp_nation, shipping.cust_nation, shipping.l_year, SUM(shipping.volume) AS revenue
33
Aggregate: groupBy=[[shipping.supp_nation, shipping.cust_nation, shipping.l_year]], aggr=[[SUM(shipping.volume)]]
4-
Projection: shipping.supp_nation, shipping.cust_nation, shipping.l_year, shipping.volume, alias=shipping
5-
Projection: n1.n_name AS supp_nation, n2.n_name AS cust_nation, datepart(Utf8("YEAR"), lineitem.l_shipdate) AS l_year, CAST(lineitem.l_extendedprice AS Decimal128(38, 4)) * CAST(Decimal128(Some(100),23,2) - CAST(lineitem.l_discount AS Decimal128(23, 2)) AS Decimal128(38, 4)) AS volume, alias=shipping
4+
Projection: supp_nation, cust_nation, l_year, volume, alias=shipping
5+
Projection: n1.n_name AS supp_nation, n2.n_name AS cust_nation, datepart(Utf8("YEAR"), lineitem.l_shipdate) AS l_year, CAST(lineitem.l_extendedprice AS Decimal128(38, 4)) * CAST(Decimal128(Some(100),23,2) - CAST(lineitem.l_discount AS Decimal128(23, 2)) AS Decimal128(38, 4)) AS volume
66
Filter: (n1.n_name = Utf8("FRANCE") OR n2.n_name = Utf8("FRANCE")) AND (n2.n_name = Utf8("GERMANY") OR n1.n_name = Utf8("GERMANY"))
77
Inner Join: customer.c_nationkey = n2.n_nationkey
88
Inner Join: supplier.s_nationkey = n1.n_nationkey

benchmarks/expected-plans/q8.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Sort: all_nations.o_year ASC NULLS LAST
22
Projection: all_nations.o_year, SUM(CASE WHEN all_nations.nation = Utf8("BRAZIL") THEN all_nations.volume ELSE Int64(0) END) / SUM(all_nations.volume) AS mkt_share
33
Aggregate: groupBy=[[all_nations.o_year]], aggr=[[SUM(CASE WHEN all_nations.nation = Utf8("BRAZIL") THEN all_nations.volume ELSE Decimal128(Some(0),38,4) END) AS SUM(CASE WHEN all_nations.nation = Utf8("BRAZIL") THEN all_nations.volume ELSE Int64(0) END), SUM(all_nations.volume)]]
4-
Projection: all_nations.o_year, all_nations.volume, all_nations.nation, alias=all_nations
5-
Projection: datepart(Utf8("YEAR"), orders.o_orderdate) AS o_year, CAST(lineitem.l_extendedprice AS Decimal128(38, 4)) * CAST(Decimal128(Some(100),23,2) - CAST(lineitem.l_discount AS Decimal128(23, 2)) AS Decimal128(38, 4)) AS volume, n2.n_name AS nation, alias=all_nations
4+
Projection: o_year, volume, nation, alias=all_nations
5+
Projection: datepart(Utf8("YEAR"), orders.o_orderdate) AS o_year, CAST(lineitem.l_extendedprice AS Decimal128(38, 4)) * CAST(Decimal128(Some(100),23,2) - CAST(lineitem.l_discount AS Decimal128(23, 2)) AS Decimal128(38, 4)) AS volume, n2.n_name AS nation
66
Inner Join: n1.n_regionkey = region.r_regionkey
77
Inner Join: supplier.s_nationkey = n2.n_nationkey
88
Inner Join: customer.c_nationkey = n1.n_nationkey

benchmarks/expected-plans/q9.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Sort: profit.nation ASC NULLS LAST, profit.o_year DESC NULLS FIRST
22
Projection: profit.nation, profit.o_year, SUM(profit.amount) AS sum_profit
33
Aggregate: groupBy=[[profit.nation, profit.o_year]], aggr=[[SUM(profit.amount)]]
4-
Projection: profit.nation, profit.o_year, profit.amount, alias=profit
5-
Projection: nation.n_name AS nation, datepart(Utf8("YEAR"), orders.o_orderdate) AS o_year, CAST(lineitem.l_extendedprice AS Decimal128(38, 4)) * CAST(Decimal128(Some(100),23,2) - CAST(lineitem.l_discount AS Decimal128(23, 2)) AS Decimal128(38, 4)) - CAST(partsupp.ps_supplycost * lineitem.l_quantity AS Decimal128(38, 4)) AS amount, alias=profit
4+
Projection: nation, o_year, amount, alias=profit
5+
Projection: nation.n_name AS nation, datepart(Utf8("YEAR"), orders.o_orderdate) AS o_year, CAST(lineitem.l_extendedprice AS Decimal128(38, 4)) * CAST(Decimal128(Some(100),23,2) - CAST(lineitem.l_discount AS Decimal128(23, 2)) AS Decimal128(38, 4)) - CAST(partsupp.ps_supplycost * lineitem.l_quantity AS Decimal128(38, 4)) AS amount
66
Inner Join: supplier.s_nationkey = nation.n_nationkey
77
Inner Join: lineitem.l_orderkey = orders.o_orderkey
88
Inner Join: lineitem.l_suppkey = partsupp.ps_suppkey, lineitem.l_partkey = partsupp.ps_partkey

datafusion/core/tests/sql/explain_analyze.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async fn explain_analyze_baseline_metrics() {
6464
);
6565
assert_metrics!(
6666
&formatted,
67-
"SortExec: [c1@0 ASC NULLS LAST]",
67+
"SortExec: [c1@1 ASC NULLS LAST]",
6868
"metrics=[output_rows=5, elapsed_compute="
6969
);
7070
assert_metrics!(
@@ -746,7 +746,7 @@ async fn test_physical_plan_display_indent_multi_children() {
746746
" ProjectionExec: expr=[c2@0 as c2]",
747747
" ProjectionExec: expr=[c1@0 as c2]",
748748
" RepartitionExec: partitioning=RoundRobinBatch(9000)",
749-
" CsvExec: files=[ARROW_TEST_DATA/csv/aggregate_test_100.csv], has_header=true, limit=None, projection=[c1]",
749+
" CsvExec: files=[ARROW_TEST_DATA/csv/aggregate_test_100.csv], has_header=true, limit=None, projection=[c1, c2]",
750750
];
751751

752752
let normalizer = ExplainNormalizer::new();

datafusion/core/tests/sql/joins.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,8 +1521,8 @@ async fn reduce_left_join_3() -> Result<()> {
15211521
"Explain [plan_type:Utf8, plan:Utf8]",
15221522
" Projection: t3.t1_id, t3.t1_name, t3.t1_int, t2.t2_id, t2.t2_name, t2.t2_int [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
15231523
" Left Join: t3.t1_int = t2.t2_int [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
1524-
" Projection: t3.t1_id, t3.t1_name, t3.t1_int, alias=t3 [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
1525-
" Projection: t1.t1_id, t1.t1_name, t1.t1_int, alias=t3 [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
1524+
" Projection: t1.t1_id, t1.t1_name, t1.t1_int, alias=t3 [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
1525+
" Projection: t1.t1_id, t1.t1_name, t1.t1_int [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
15261526
" Inner Join: t1.t1_id = t2.t2_id [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
15271527
" Filter: CAST(t1.t1_id AS Int64) < Int64(100) [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
15281528
" TableScan: t1 projection=[t1_id, t1_name, t1_int] [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",

datafusion/core/tests/sql/subqueries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ order by cntrycode;"#;
382382
let expected = r#"Sort: custsale.cntrycode ASC NULLS LAST
383383
Projection: custsale.cntrycode, COUNT(UInt8(1)) AS numcust, SUM(custsale.c_acctbal) AS totacctbal
384384
Aggregate: groupBy=[[custsale.cntrycode]], aggr=[[COUNT(UInt8(1)), SUM(custsale.c_acctbal)]]
385-
Projection: custsale.cntrycode, custsale.c_acctbal, alias=custsale
386-
Projection: substr(customer.c_phone, Int64(1), Int64(2)) AS cntrycode, customer.c_acctbal, alias=custsale
385+
Projection: cntrycode, customer.c_acctbal, alias=custsale
386+
Projection: substr(customer.c_phone, Int64(1), Int64(2)) AS cntrycode, customer.c_acctbal
387387
Filter: CAST(customer.c_acctbal AS Decimal128(19, 6)) > __sq_1.__value
388388
CrossJoin:
389389
LeftAnti Join: customer.c_custkey = orders.o_custkey

datafusion/sql/src/planner.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
781781
let normalized_alias = alias.as_ref().map(|a| normalize_ident(&a.name));
782782
let logical_plan = self.query_to_plan_with_alias(
783783
*subquery,
784-
normalized_alias.clone(),
784+
None,
785785
ctes,
786786
outer_query_schema,
787787
)?;
@@ -3193,10 +3193,10 @@ mod tests {
31933193
) AS a
31943194
) AS b";
31953195
let expected = "Projection: b.fn2, b.last_name\
3196-
\n Projection: b.fn2, b.last_name, b.birth_date, alias=b\
3197-
\n Projection: a.fn1 AS fn2, a.last_name, a.birth_date, alias=b\
3198-
\n Projection: a.fn1, a.last_name, a.birth_date, a.age, alias=a\
3199-
\n Projection: person.first_name AS fn1, person.last_name, person.birth_date, person.age, alias=a\
3196+
\n Projection: fn2, a.last_name, a.birth_date, alias=b\
3197+
\n Projection: a.fn1 AS fn2, a.last_name, a.birth_date\
3198+
\n Projection: fn1, person.last_name, person.birth_date, person.age, alias=a\
3199+
\n Projection: person.first_name AS fn1, person.last_name, person.birth_date, person.age\
32003200
\n TableScan: person";
32013201
quick_test(sql, expected);
32023202
}
@@ -3213,8 +3213,8 @@ mod tests {
32133213

32143214
let expected = "Projection: a.fn1, a.age\
32153215
\n Filter: a.fn1 = Utf8(\"X\") AND a.age < Int64(30)\
3216-
\n Projection: a.fn1, a.age, alias=a\
3217-
\n Projection: person.first_name AS fn1, person.age, alias=a\
3216+
\n Projection: fn1, person.age, alias=a\
3217+
\n Projection: person.first_name AS fn1, person.age\
32183218
\n Filter: person.age > Int64(20)\
32193219
\n TableScan: person";
32203220

@@ -3564,8 +3564,8 @@ mod tests {
35643564
"SELECT * FROM (SELECT first_name, last_name FROM person) AS a GROUP BY first_name, last_name",
35653565
"Projection: a.first_name, a.last_name\
35663566
\n Aggregate: groupBy=[[a.first_name, a.last_name]], aggr=[[]]\
3567-
\n Projection: a.first_name, a.last_name, alias=a\
3568-
\n Projection: person.first_name, person.last_name, alias=a\
3567+
\n Projection: person.first_name, person.last_name, alias=a\
3568+
\n Projection: person.first_name, person.last_name\
35693569
\n TableScan: person",
35703570
);
35713571
}
@@ -4473,13 +4473,13 @@ mod tests {
44734473
\n Union\
44744474
\n Projection: CAST(x.a AS Float64) AS a\
44754475
\n Aggregate: groupBy=[[x.a]], aggr=[[]]\
4476-
\n Projection: x.a, alias=x\
4477-
\n Projection: Int64(1) AS a, alias=x\
4476+
\n Projection: a, alias=x\
4477+
\n Projection: Int64(1) AS a\
44784478
\n EmptyRelation\
44794479
\n Projection: x.a\
44804480
\n Aggregate: groupBy=[[x.a]], aggr=[[]]\
4481-
\n Projection: x.a, alias=x\
4482-
\n Projection: Float64(1.1) AS a, alias=x\
4481+
\n Projection: a, alias=x\
4482+
\n Projection: Float64(1.1) AS a\
44834483
\n EmptyRelation";
44844484
quick_test(sql, expected);
44854485
}
@@ -4490,13 +4490,13 @@ mod tests {
44904490
let expected = "Union\
44914491
\n Projection: CAST(Float64(0) + x.a AS Float64) AS Float64(0) + x.a\
44924492
\n Aggregate: groupBy=[[CAST(Float64(0) + x.a AS Int32)]], aggr=[[]]\
4493-
\n Projection: x.a, alias=x\
4494-
\n Projection: Int64(1) AS a, alias=x\
4493+
\n Projection: a, alias=x\
4494+
\n Projection: Int64(1) AS a\
44954495
\n EmptyRelation\
44964496
\n Projection: Float64(2.1) + x.a\
44974497
\n Aggregate: groupBy=[[Float64(2.1) + x.a]], aggr=[[]]\
4498-
\n Projection: x.a, alias=x\
4499-
\n Projection: Int64(1) AS a, alias=x\
4498+
\n Projection: a, alias=x\
4499+
\n Projection: Int64(1) AS a\
45004500
\n EmptyRelation";
45014501
quick_test(sql, expected);
45024502
}
@@ -4507,13 +4507,13 @@ mod tests {
45074507
let expected = "Union\
45084508
\n Projection: CAST(x.a AS Float64) AS a1\
45094509
\n Aggregate: groupBy=[[x.a]], aggr=[[]]\
4510-
\n Projection: x.a, alias=x\
4511-
\n Projection: Int64(1) AS a, alias=x\
4510+
\n Projection: a, alias=x\
4511+
\n Projection: Int64(1) AS a\
45124512
\n EmptyRelation\
45134513
\n Projection: x.a AS a1\
45144514
\n Aggregate: groupBy=[[x.a]], aggr=[[]]\
4515-
\n Projection: x.a, alias=x\
4516-
\n Projection: Float64(1.1) AS a, alias=x\
4515+
\n Projection: a, alias=x\
4516+
\n Projection: Float64(1.1) AS a\
45174517
\n EmptyRelation";
45184518
quick_test(sql, expected);
45194519
}

0 commit comments

Comments
 (0)