mihaibudiu commented on code in PR #5031:
URL: https://github.com/apache/calcite/pull/5031#discussion_r3445498352


##########
core/src/test/resources/sql/unnest.iq:
##########
@@ -626,4 +626,222 @@ WHERE (
 
 !ok
 
+# Tests for [CALCITE-7608] Introduce a SelectMany operator
+!use scott
+!set hep-rules "
++CoreRules.CORRELATE_UNCOLLECT_TO_SELECT_MANY"
+
+# Validated on Postgres by replacing COLLECT with ARRAY_AGG
+SELECT u.x, z
+FROM (
+    SELECT x, COLLECT(y) as ys
+    FROM (VALUES (1, 1), (2, 2), (1, 3)) AS t (x, y)
+    GROUP BY x) AS u,
+  UNNEST(u.ys) AS z;
++---+---+
+| X | Z |
++---+---+
+| 1 | 1 |
+| 1 | 3 |
+| 2 | 2 |
++---+---+
+(3 rows)
+
+!ok
+EnumerableSelectMany(passthrough=[[X]], collectionFields=[[YS]])
+  EnumerableAggregate(group=[{0}], YS=[COLLECT($1)])
+    EnumerableValues(tuples=[[{ 1, 1 }, { 2, 2 }, { 1, 3 }]])
+!plan
+
+# Lateral UNNEST with ordinality
+# Validated on Postgres by replacing COLLECT with ARRAY_AGG
+SELECT u.x, z, o
+FROM (
+    SELECT x, collect(y) as ys
+    FROM (VALUES (10, 'a'), (10, 'b'), (20, 'c')) AS t (x, y)
+    GROUP BY x) AS u,
+  UNNEST(u.ys) WITH ORDINALITY AS t(z, o);
++----+---+---+
+| X  | Z | O |
++----+---+---+
+| 10 | a | 1 |
+| 10 | b | 2 |
+| 20 | c | 1 |
++----+---+---+
+(3 rows)
+
+!ok
+EnumerableSelectMany(passthrough=[[X]], collectionFields=[[YS]], 
withOrdinality=[true])
+  EnumerableAggregate(group=[{0}], YS=[COLLECT($1)])
+    EnumerableValues(tuples=[[{ 10, 'a' }, { 10, 'b' }, { 20, 'c' }]])
+!plan
+
+# Two scalar arrays of different lengths: shorter is padded with NULL.
+# Pass-through field n is carried unchanged.
+# Validated on Postgres
+SELECT n, a, b
+FROM (SELECT 'test' AS n, ARRAY[1, 2, 3] AS arr1, ARRAY[10, 20] AS arr2) AS u,
+UNNEST(u.arr1, u.arr2) AS t(a, b);

Review Comment:
   to make the output deterministic?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to