Skip to content

Commit 10dff75

Browse files
committed
#17411 Add additional SQL logic tests
1 parent 6a88408 commit 10dff75

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
a,b
2+
1,0
3+
0,2
4+
1,2
5+
0,4
6+
5,0
7+
3,3
8+
4,3

datafusion/sqllogictest/test_files/order.slt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,3 +1517,40 @@ SELECT address, zip FROM addresses ORDER BY ALL;
15171517
111 Duck Duck Goose Ln 11111
15181518
111 Duck Duck Goose Ln 11111-0001
15191519
123 Quack Blvd 11111
1520+
1521+
# Create a table with an order clause that's not a simple column reference
1522+
statement ok
1523+
CREATE EXTERNAL TABLE ordered (
1524+
a BIGINT NOT NULL,
1525+
b BIGINT NOT NULL
1526+
)
1527+
STORED AS CSV
1528+
LOCATION 'data/composite_order.csv'
1529+
OPTIONS ('format.has_header' 'true')
1530+
WITH ORDER (a + b);
1531+
1532+
# Simple query should be just a table scan
1533+
query TT
1534+
EXPLAIN SELECT * from ordered;
1535+
----
1536+
physical_plan DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/sqllogictest/data/composite_order.csv]]}, projection=[a, b], output_ordering=[a@0 + b@1 ASC NULLS LAST], file_type=csv, has_header=true
1537+
1538+
# Query ordered by the declared order should be just a table scan
1539+
query TT
1540+
EXPLAIN SELECT * from ordered ORDER BY (a + b);
1541+
----
1542+
physical_plan DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/sqllogictest/data/composite_order.csv]]}, projection=[a, b], output_ordering=[a@0 + b@1 ASC NULLS LAST], file_type=csv, has_header=true
1543+
1544+
# Order equivalence handling should make this query a simple table scan
1545+
query TT
1546+
EXPLAIN SELECT * from ordered ORDER BY -(a + b) desc nulls last;
1547+
----
1548+
physical_plan DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/sqllogictest/data/composite_order.csv]]}, projection=[a, b], output_ordering=[a@0 + b@1 ASC NULLS LAST], file_type=csv, has_header=true
1549+
1550+
# Ordering by another column requires a sort
1551+
query TT
1552+
EXPLAIN SELECT * from ordered ORDER BY a;
1553+
----
1554+
physical_plan
1555+
01)SortExec: expr=[a@0 ASC NULLS LAST], preserve_partitioning=[false]
1556+
02)--DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/sqllogictest/data/composite_order.csv]]}, projection=[a, b], output_ordering=[a@0 + b@1 ASC NULLS LAST], file_type=csv, has_header=true

0 commit comments

Comments
 (0)