@@ -11,10 +11,12 @@ include ../setup.slt.no
1111statement ok
1212SET 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.
1616statement 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
1921statement ok
2022INSERT 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.
3231query 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----
3534logical_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]
3837physical_plan DataSourceExec: file_groups={<slt:ignore>}, projection=[array_length(a@1) as len], file_type=vortex
3938
4039query 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----
43423
44434
@@ -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`.
5049query 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----
53523
54534
@@ -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.
6059query 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----
63623
64634
@@ -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).
7069query 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----
73721
74732
@@ -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).
8079query 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----
8382logical_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)]
8786physical_plan DataSourceExec: file_groups={<slt:ignore>}, projection=[id], file_type=vortex, predicate: array_length(a@1) >= 4
8887
8988query 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----
92912
93924
9493
9594# array_length on the same column in both SELECT and WHERE produces the correct result.
9695query 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----
100984
101995
102100
103101# array_length filtering a different column than the projection.
104102query 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----
1081053 1
1091064 5
110107
111108# array_length over different columns in both SELECT and WHERE.
112109query 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----
1161124 2
1171131 3
@@ -125,13 +121,12 @@ statement ok
125121SET datafusion.execution.target_partitions = 2;
126122
127123query 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----
131126logical_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)]
135130physical_plan
13613101)ProjectionExec: expr=[array_length(a@0) as len]
13713202)--RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1
@@ -143,11 +138,10 @@ statement ok
143138SET datafusion.execution.target_partitions = 1;
144139
145140query 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----
149143logical_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)]
153147physical_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