Skip to content

Commit 80f3614

Browse files
committed
Add some tests to flat_map_elimination.spec
1 parent c0ec801 commit 80f3614

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/transform/tests/test_transforms/flatmap_to_map.spec renamed to src/transform/tests/test_transforms/flat_map_elimination.spec

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ FlatMap wrap3(0, 1, 2, 3)
8383
## Support for unnest_~ calls
8484
## --------------------------
8585

86-
# Rewrite possible for `unnset_array`
86+
# Rewrite possible for `unnest_array`
8787
# Example SQL: select unnest(array[f1]) from t1 where f1 = 5;
8888
apply pipeline=flat_map_elimination
8989
FlatMap unnest_array({5})
@@ -101,15 +101,15 @@ FlatMap unnest_list([5])
101101
Map (5)
102102
Get t0
103103

104-
# Rewrite not possible: unnest_array(-) argument is not resuced
104+
# Rewrite not possible: unnest_array(-) argument is not reduced to a literal
105105
apply pipeline=flat_map_elimination
106106
FlatMap unnest_array(array[5])
107107
Get t0
108108
----
109109
FlatMap unnest_array(array[5])
110110
Get t0
111111

112-
# Rewrite not possible: unnest_list(-) argument is not resuced
112+
# Rewrite not possible: unnest_list(-) argument is not reduced to a literal
113113
apply pipeline=flat_map_elimination
114114
FlatMap unnest_list(list[5])
115115
Get t0
@@ -119,16 +119,37 @@ FlatMap unnest_list(list[5])
119119

120120
# Rewrite not possible: unnest_array(-) argument is not a singleton
121121
apply pipeline=flat_map_elimination
122+
FlatMap unnest_array({5, 6})
123+
Get t0
124+
----
125+
FlatMap unnest_array({5, 6})
126+
Get t0
127+
128+
# Rewrite not possible: unnest_list(-) argument is not a singleton
129+
apply pipeline=flat_map_elimination
122130
FlatMap unnest_list([5, 6])
123131
Get t0
124132
----
125133
FlatMap unnest_list([5, 6])
126134
Get t0
127135

128-
# Rewrite not possible: unnest_list(-) argument is not a singleton
136+
# generate_series can produce 0, 1, or more rows, based on its arguments
129137
apply pipeline=flat_map_elimination
130-
FlatMap unnest_list(list[5])
138+
FlatMap generate_series(5, 2, 1)
131139
Get t0
132140
----
133-
FlatMap unnest_list(list[5])
141+
Constant <empty>
142+
143+
apply pipeline=flat_map_elimination
144+
FlatMap generate_series(5, 5, 1)
145+
Get t0
146+
----
147+
Map (5)
134148
Get t0
149+
150+
apply pipeline=flat_map_elimination
151+
FlatMap generate_series(5, 6, 1)
152+
Get t0
153+
----
154+
FlatMap generate_series(5, 6, 1)
155+
Get

test/sqllogictest/window_funcs.slt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6874,7 +6874,8 @@ NULL 11 NULL 22 22 22 {22}
68746874
# than one window function call in one test, because we currently forget the key information after a window function
68756875
# call (even when `ReduceElision` simplifies the window function call).
68766876
# TODO: Add an optimization that eliminates a Map-FlatMap pair where the Map is just creating a 1-element list on which
6877-
# the FlatMap is immediately calling `unnest_list`.
6877+
# the FlatMap is immediately calling `unnest_list`. We could use the `Equivalences` analysis for this, which would tell
6878+
# us that the column reference in `unnest_list` is equal to a `list_create` with 1 argument.
68786879
query T multiline
68796880
EXPLAIN OPTIMIZED PLAN WITH(keys, humanized expressions) AS VERBOSE TEXT FOR
68806881
SELECT

0 commit comments

Comments
 (0)