Skip to content

Commit 6b3fdfe

Browse files
committed
sqllogictest: back list_length test by a Vortex external table
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
1 parent 17cbf26 commit 6b3fdfe

1 file changed

Lines changed: 28 additions & 34 deletions

File tree

vortex-sqllogictest/slt/datafusion/list_length_pushdown.slt

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ include ../setup.slt.no
1111
statement ok
1212
SET vortex.projection_pushdown = true;
1313

14-
# Two list columns so we can exercise list-length pushdown over the same and different columns,
15-
# in both SELECT and WHERE. Row 5's `b` is an empty list (length 0).
14+
# A Vortex-backed external table with two list columns, so we can exercise list-length pushdown
15+
# over the same and different columns in both SELECT and WHERE. Row 5's `b` is an empty list.
1616
statement ok
17-
CREATE TABLE list_test (id INT, a INT[], b INT[]);
17+
CREATE EXTERNAL TABLE list_test (id INT, a INT[], b INT[])
18+
STORED AS vortex
19+
LOCATION '${WORK_DIR}/list_test/';
1820

1921
statement ok
2022
INSERT INTO list_test VALUES
@@ -24,21 +26,18 @@ INSERT INTO list_test VALUES
2426
(4, [90, 100, 110, 120, 130], [7, 8, 9, 10]),
2527
(5, [140, 150], []);
2628

27-
statement ok
28-
COPY (SELECT * FROM list_test) TO '${WORK_DIR}/list-length.vortex';
29-
3029
# array_length(a) projection is pushed into the scan: it appears in the DataSourceExec
3130
# projection with no ProjectionExec above the scan.
3231
query TT
33-
EXPLAIN SELECT array_length(a) AS len FROM '${WORK_DIR}/list-length.vortex';
32+
EXPLAIN SELECT array_length(a) AS len FROM list_test;
3433
----
3534
logical_plan
36-
01)Projection: array_length(${WORK_DIR}/list-length.vortex.a) AS len
37-
02)--TableScan: ${WORK_DIR}/list-length.vortex projection=[a]
35+
01)Projection: array_length(list_test.a) AS len
36+
02)--TableScan: list_test projection=[a]
3837
physical_plan DataSourceExec: file_groups={<slt:ignore>}, projection=[array_length(a@1) as len], file_type=vortex
3938

4039
query I
41-
SELECT array_length(a) FROM '${WORK_DIR}/list-length.vortex' ORDER BY id;
40+
SELECT array_length(a) FROM list_test ORDER BY id;
4241
----
4342
3
4443
4
@@ -48,7 +47,7 @@ SELECT array_length(a) FROM '${WORK_DIR}/list-length.vortex' ORDER BY id;
4847

4948
# `list_length` is an alias for `array_length`.
5049
query I
51-
SELECT list_length(a) FROM '${WORK_DIR}/list-length.vortex' ORDER BY id;
50+
SELECT list_length(a) FROM list_test ORDER BY id;
5251
----
5352
3
5453
4
@@ -58,7 +57,7 @@ SELECT list_length(a) FROM '${WORK_DIR}/list-length.vortex' ORDER BY id;
5857

5958
# The explicit first-dimension form `array_length(a, 1)` is equivalent.
6059
query I
61-
SELECT array_length(a, 1) FROM '${WORK_DIR}/list-length.vortex' ORDER BY id;
60+
SELECT array_length(a, 1) FROM list_test ORDER BY id;
6261
----
6362
3
6463
4
@@ -68,7 +67,7 @@ SELECT array_length(a, 1) FROM '${WORK_DIR}/list-length.vortex' ORDER BY id;
6867

6968
# array_length over the other list column, including the empty list (length 0, not NULL).
7069
query I
71-
SELECT array_length(b) FROM '${WORK_DIR}/list-length.vortex' ORDER BY id;
70+
SELECT array_length(b) FROM list_test ORDER BY id;
7271
----
7372
1
7473
2
@@ -78,40 +77,37 @@ SELECT array_length(b) FROM '${WORK_DIR}/list-length.vortex' ORDER BY id;
7877

7978
# array_length in WHERE is pushed into the scan as a predicate (no FilterExec above the scan).
8079
query TT
81-
EXPLAIN SELECT id FROM '${WORK_DIR}/list-length.vortex' WHERE array_length(a) >= 4;
80+
EXPLAIN SELECT id FROM list_test WHERE array_length(a) >= 4;
8281
----
8382
logical_plan
84-
01)Projection: ${WORK_DIR}/list-length.vortex.id
85-
02)--Filter: array_length(${WORK_DIR}/list-length.vortex.a) >= UInt64(4)
86-
03)----TableScan: ${WORK_DIR}/list-length.vortex projection=[id, a], partial_filters=[array_length(${WORK_DIR}/list-length.vortex.a) >= UInt64(4)]
83+
01)Projection: list_test.id
84+
02)--Filter: array_length(list_test.a) >= UInt64(4)
85+
03)----TableScan: list_test projection=[id, a], partial_filters=[array_length(list_test.a) >= UInt64(4)]
8786
physical_plan DataSourceExec: file_groups={<slt:ignore>}, projection=[id], file_type=vortex, predicate: array_length(a@1) >= 4
8887

8988
query I
90-
SELECT id FROM '${WORK_DIR}/list-length.vortex' WHERE array_length(a) >= 4 ORDER BY id;
89+
SELECT id FROM list_test WHERE array_length(a) >= 4 ORDER BY id;
9190
----
9291
2
9392
4
9493

9594
# array_length on the same column in both SELECT and WHERE produces the correct result.
9695
query I
97-
SELECT array_length(a) FROM '${WORK_DIR}/list-length.vortex'
98-
WHERE array_length(a) >= 4 ORDER BY id;
96+
SELECT array_length(a) FROM list_test WHERE array_length(a) >= 4 ORDER BY id;
9997
----
10098
4
10199
5
102100

103101
# array_length filtering a different column than the projection.
104102
query II
105-
SELECT id, array_length(a) FROM '${WORK_DIR}/list-length.vortex'
106-
WHERE array_length(b) >= 3 ORDER BY id;
103+
SELECT id, array_length(a) FROM list_test WHERE array_length(b) >= 3 ORDER BY id;
107104
----
108105
3 1
109106
4 5
110107

111108
# array_length over different columns in both SELECT and WHERE.
112109
query II
113-
SELECT array_length(a), array_length(b) FROM '${WORK_DIR}/list-length.vortex'
114-
WHERE array_length(b) >= 2 ORDER BY id;
110+
SELECT array_length(a), array_length(b) FROM list_test WHERE array_length(b) >= 2 ORDER BY id;
115111
----
116112
4 2
117113
1 3
@@ -125,13 +121,12 @@ statement ok
125121
SET datafusion.execution.target_partitions = 2;
126122

127123
query TT
128-
EXPLAIN SELECT array_length(a) AS len FROM '${WORK_DIR}/list-length.vortex'
129-
WHERE array_length(a) >= 4;
124+
EXPLAIN SELECT array_length(a) AS len FROM list_test WHERE array_length(a) >= 4;
130125
----
131126
logical_plan
132-
01)Projection: array_length(${WORK_DIR}/list-length.vortex.a) AS len
133-
02)--Filter: array_length(${WORK_DIR}/list-length.vortex.a) >= UInt64(4)
134-
03)----TableScan: ${WORK_DIR}/list-length.vortex projection=[a], partial_filters=[array_length(${WORK_DIR}/list-length.vortex.a) >= UInt64(4)]
127+
01)Projection: array_length(list_test.a) AS len
128+
02)--Filter: array_length(list_test.a) >= UInt64(4)
129+
03)----TableScan: list_test projection=[a], partial_filters=[array_length(list_test.a) >= UInt64(4)]
135130
physical_plan
136131
01)ProjectionExec: expr=[array_length(a@0) as len]
137132
02)--RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1
@@ -143,11 +138,10 @@ statement ok
143138
SET datafusion.execution.target_partitions = 1;
144139

145140
query TT
146-
EXPLAIN SELECT array_length(a) AS len FROM '${WORK_DIR}/list-length.vortex'
147-
WHERE array_length(a) >= 4;
141+
EXPLAIN SELECT array_length(a) AS len FROM list_test WHERE array_length(a) >= 4;
148142
----
149143
logical_plan
150-
01)Projection: array_length(${WORK_DIR}/list-length.vortex.a) AS len
151-
02)--Filter: array_length(${WORK_DIR}/list-length.vortex.a) >= UInt64(4)
152-
03)----TableScan: ${WORK_DIR}/list-length.vortex projection=[a], partial_filters=[array_length(${WORK_DIR}/list-length.vortex.a) >= UInt64(4)]
144+
01)Projection: array_length(list_test.a) AS len
145+
02)--Filter: array_length(list_test.a) >= UInt64(4)
146+
03)----TableScan: list_test projection=[a], partial_filters=[array_length(list_test.a) >= UInt64(4)]
153147
physical_plan DataSourceExec: file_groups={<slt:ignore>}, projection=[array_length(a@1) as len], file_type=vortex, predicate: array_length(a@1) >= 4

0 commit comments

Comments
 (0)