Skip to content

Commit 6c5c5c1

Browse files
authored
fix union view (#15300)
1 parent a181e1d commit 6c5c5c1

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

datafusion/sqllogictest/test_files/union.slt

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ INSERT INTO u2 VALUES (20, 20), (40, 40);
896896

897897
statement ok
898898
CREATE VIEW v1 AS
899-
SELECT y FROM u1 UNION ALL SELECT y FROM u2 ORDER BY y;
899+
SELECT y FROM u1 UNION ALL SELECT y FROM u2 ORDER BY y;
900900

901901
query I
902902
SELECT * FROM (SELECT y FROM u1 UNION ALL SELECT y FROM u2) ORDER BY y;
@@ -907,11 +907,56 @@ SELECT * FROM (SELECT y FROM u1 UNION ALL SELECT y FROM u2) ORDER BY y;
907907
20
908908
40
909909

910+
query TT
911+
explain SELECT * FROM (SELECT y FROM u1 UNION ALL SELECT y FROM u2) ORDER BY y;
912+
----
913+
logical_plan
914+
01)Sort: y ASC NULLS LAST
915+
02)--Union
916+
03)----Projection: CAST(u1.y AS Int64) AS y
917+
04)------TableScan: u1 projection=[y]
918+
05)----TableScan: u2 projection=[y]
919+
physical_plan
920+
01)SortPreservingMergeExec: [y@0 ASC NULLS LAST]
921+
02)--UnionExec
922+
03)----SortExec: expr=[y@0 ASC NULLS LAST], preserve_partitioning=[true]
923+
04)------ProjectionExec: expr=[CAST(y@0 AS Int64) as y]
924+
05)--------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
925+
06)----------DataSourceExec: partitions=1, partition_sizes=[1]
926+
07)----SortExec: expr=[y@0 ASC NULLS LAST], preserve_partitioning=[false]
927+
08)------DataSourceExec: partitions=1, partition_sizes=[1]
928+
929+
# optimize_subquery_sort in create_relation removes Sort so the result is not sorted.
910930
query I
911931
SELECT * FROM v1;
912932
----
913-
1
914-
3
915-
3
916933
20
917934
40
935+
3
936+
3
937+
1
938+
939+
query TT
940+
explain SELECT * FROM v1;
941+
----
942+
logical_plan
943+
01)SubqueryAlias: v1
944+
02)--Union
945+
03)----Projection: CAST(u1.y AS Int64) AS y
946+
04)------TableScan: u1 projection=[y]
947+
05)----TableScan: u2 projection=[y]
948+
physical_plan
949+
01)UnionExec
950+
02)--ProjectionExec: expr=[CAST(y@0 AS Int64) as y]
951+
03)----RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
952+
04)------DataSourceExec: partitions=1, partition_sizes=[1]
953+
05)--DataSourceExec: partitions=1, partition_sizes=[1]
954+
955+
statement count 0
956+
drop view v1;
957+
958+
statement count 0
959+
drop table u1;
960+
961+
statement count 0
962+
drop table u2;

0 commit comments

Comments
 (0)