Skip to content

Commit 6e422e0

Browse files
authored
Minor: Fix invalid query in test (#15131)
* Minor: Fix invalid query in test * other query
1 parent 0f24c61 commit 6e422e0

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

datafusion/sqllogictest/test_files/order.slt

+34-27
Original file line numberDiff line numberDiff line change
@@ -986,17 +986,26 @@ statement ok
986986
create table t(a0 int, a int, b int, c int) as values (1, 2, 3, 4), (5, 6, 7, 8);
987987

988988
# expect this query to run successfully, not error
989+
query IIII
990+
select * from (select c, a, NULL::int as a0, b from t order by a, c) t1
991+
union all
992+
select * from (select c, NULL::int as a, a0, b from t order by a0, c) t2
993+
order by c, a, a0, b
994+
limit 2;
995+
----
996+
4 2 NULL 3
997+
4 NULL 1 3
998+
989999
query III
9901000
select * from (select c, a, NULL::int as a0 from t order by a, c) t1
9911001
union all
9921002
select * from (select c, NULL::int as a, a0 from t order by a0, c) t2
993-
order by c, a, a0, b
1003+
order by c, a, a0
9941004
limit 2;
9951005
----
9961006
4 2 NULL
9971007
4 NULL 1
9981008

999-
10001009
# Casting from numeric to string types breaks the ordering
10011010
statement ok
10021011
CREATE EXTERNAL TABLE ordered_table (
@@ -1232,43 +1241,41 @@ physical_plan
12321241

12331242
# Test: inputs into union with different orderings
12341243
query TT
1235-
explain select * from (select b, c, a, NULL::int as a0 from ordered_table order by a, c) t1
1244+
explain select * from (select b, c, a, NULL::int as a0, d from ordered_table order by a, c) t1
12361245
union all
1237-
select * from (select b, c, NULL::int as a, a0 from ordered_table order by a0, c) t2
1246+
select * from (select b, c, NULL::int as a, a0, d from ordered_table order by a0, c) t2
12381247
order by d, c, a, a0, b
12391248
limit 2;
12401249
----
12411250
logical_plan
1242-
01)Projection: t1.b, t1.c, t1.a, t1.a0
1243-
02)--Sort: t1.d ASC NULLS LAST, t1.c ASC NULLS LAST, t1.a ASC NULLS LAST, t1.a0 ASC NULLS LAST, t1.b ASC NULLS LAST, fetch=2
1244-
03)----Union
1245-
04)------SubqueryAlias: t1
1246-
05)--------Projection: ordered_table.b, ordered_table.c, ordered_table.a, Int32(NULL) AS a0, ordered_table.d
1247-
06)----------TableScan: ordered_table projection=[a, b, c, d]
1248-
07)------SubqueryAlias: t2
1249-
08)--------Projection: ordered_table.b, ordered_table.c, Int32(NULL) AS a, ordered_table.a0, ordered_table.d
1250-
09)----------TableScan: ordered_table projection=[a0, b, c, d]
1251+
01)Sort: t1.d ASC NULLS LAST, t1.c ASC NULLS LAST, t1.a ASC NULLS LAST, t1.a0 ASC NULLS LAST, t1.b ASC NULLS LAST, fetch=2
1252+
02)--Union
1253+
03)----SubqueryAlias: t1
1254+
04)------Projection: ordered_table.b, ordered_table.c, ordered_table.a, Int32(NULL) AS a0, ordered_table.d
1255+
05)--------TableScan: ordered_table projection=[a, b, c, d]
1256+
06)----SubqueryAlias: t2
1257+
07)------Projection: ordered_table.b, ordered_table.c, Int32(NULL) AS a, ordered_table.a0, ordered_table.d
1258+
08)--------TableScan: ordered_table projection=[a0, b, c, d]
12511259
physical_plan
1252-
01)ProjectionExec: expr=[b@0 as b, c@1 as c, a@2 as a, a0@3 as a0]
1253-
02)--SortPreservingMergeExec: [d@4 ASC NULLS LAST, c@1 ASC NULLS LAST, a@2 ASC NULLS LAST, a0@3 ASC NULLS LAST, b@0 ASC NULLS LAST], fetch=2
1254-
03)----UnionExec
1255-
04)------SortExec: TopK(fetch=2), expr=[d@4 ASC NULLS LAST, c@1 ASC NULLS LAST, a@2 ASC NULLS LAST, b@0 ASC NULLS LAST], preserve_partitioning=[false]
1256-
05)--------ProjectionExec: expr=[b@1 as b, c@2 as c, a@0 as a, NULL as a0, d@3 as d]
1257-
06)----------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[a, b, c, d], output_ordering=[c@2 ASC NULLS LAST], file_type=csv, has_header=true
1258-
07)------SortExec: TopK(fetch=2), expr=[d@4 ASC NULLS LAST, c@1 ASC NULLS LAST, a0@3 ASC NULLS LAST, b@0 ASC NULLS LAST], preserve_partitioning=[false]
1259-
08)--------ProjectionExec: expr=[b@1 as b, c@2 as c, NULL as a, a0@0 as a0, d@3 as d]
1260-
09)----------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[a0, b, c, d], output_ordering=[c@2 ASC NULLS LAST], file_type=csv, has_header=true
1260+
01)SortPreservingMergeExec: [d@4 ASC NULLS LAST, c@1 ASC NULLS LAST, a@2 ASC NULLS LAST, a0@3 ASC NULLS LAST, b@0 ASC NULLS LAST], fetch=2
1261+
02)--UnionExec
1262+
03)----SortExec: TopK(fetch=2), expr=[d@4 ASC NULLS LAST, c@1 ASC NULLS LAST, a@2 ASC NULLS LAST, b@0 ASC NULLS LAST], preserve_partitioning=[false]
1263+
04)------ProjectionExec: expr=[b@1 as b, c@2 as c, a@0 as a, NULL as a0, d@3 as d]
1264+
05)--------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[a, b, c, d], output_ordering=[c@2 ASC NULLS LAST], file_type=csv, has_header=true
1265+
06)----SortExec: TopK(fetch=2), expr=[d@4 ASC NULLS LAST, c@1 ASC NULLS LAST, a0@3 ASC NULLS LAST, b@0 ASC NULLS LAST], preserve_partitioning=[false]
1266+
07)------ProjectionExec: expr=[b@1 as b, c@2 as c, NULL as a, a0@0 as a0, d@3 as d]
1267+
08)--------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[a0, b, c, d], output_ordering=[c@2 ASC NULLS LAST], file_type=csv, has_header=true
12611268

12621269
# Test: run the query from above
1263-
query IIII
1264-
select * from (select b, c, a, NULL::int as a0 from ordered_table order by a, c) t1
1270+
query IIIII
1271+
select * from (select b, c, a, NULL::int as a0, d from ordered_table order by a, c) t1
12651272
union all
1266-
select * from (select b, c, NULL::int as a, a0 from ordered_table order by a0, c) t2
1273+
select * from (select b, c, NULL::int as a, a0, d from ordered_table order by a0, c) t2
12671274
order by d, c, a, a0, b
12681275
limit 2;
12691276
----
1270-
0 0 0 NULL
1271-
0 0 NULL 1
1277+
0 0 0 NULL 0
1278+
0 0 NULL 1 0
12721279

12731280

12741281
statement ok

0 commit comments

Comments
 (0)