Vladsz83 commented on code in PR #12042:
URL: https://github.com/apache/ignite/pull/12042#discussion_r2084200968


##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/UnnestIntegrationTest.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Collections;
+import org.apache.ignite.internal.util.typedef.F;
+import org.junit.Test;
+
+/**
+ * Integration test for UNNEST operator.
+ */
+public class UnnestIntegrationTest extends AbstractBasicIntegrationTest {
+    /** */
+    @Test
+    public void testUnnestSingleCollection() {
+        assertQuery("SELECT * FROM UNNEST(ARRAY[1, 2, 
3])").returns(1).returns(2).returns(3).check();
+        assertQuery("SELECT * FROM UNNEST(MAP['a', 1, 'b', 2])").returns("a", 
1).returns("b", 2).check();
+        assertQuery("SELECT * FROM UNNEST(ARRAY[ROW(1, 2), ROW(3, 
4)])").returns(1, 2).returns(3, 4).check();
+
+        // Dynamic parameters.
+        assertQuery("SELECT * FROM UNNEST(?)").withParams(F.asList(1, 
2)).returns(1).returns(2).check();
+        assertQuery("SELECT * FROM UNNEST(?)").withParams(F.asMap("a", 1, "b", 
2))
+            .returns("a", 1).returns("b", 2).check();
+        // Can't check dynamic parameters with ROW, since generic type of List 
can't be obtained in runtime.
+        // SQL type of parameter F.asList(new Object[] {1, 2}) will be derived 
as array of scalars
+        // (instead of array of rows) and UNNEST can only produce rows based 
on type derived on planner phase.
+
+        // Subquery.
+        assertQuery("SELECT * FROM UNNEST(SELECT ARRAY_AGG(a) FROM (VALUES 
(1), (2)) t(a))")
+            .returns(1).returns(2).check();
+
+        assertQuery("SELECT * FROM UNNEST(SELECT ARRAY_AGG(ROW(t.a, t.b)) FROM 
(VALUES (1, 2), (3, 4)) t(a, b))")
+            .returns(1, 2).returns(3, 4).check();
+
+        assertQuery("SELECT * FROM UNNEST(SELECT * FROM (VALUES (ARRAY[1, 2, 
3]), (ARRAY[4, 5])))")
+            .returns(1).returns(2).returns(3).returns(4).returns(5).check();
+
+        assertQuery("SELECT * FROM UNNEST(SELECT * FROM (VALUES (MAP[1, 2, 3, 
4]), (MAP[5, 6])))")
+            .returns(1, 2).returns(3, 4).returns(5, 6).check();
+
+        assertQuery("SELECT * FROM UNNEST(SELECT * FROM (VALUES (ARRAY[ROW(1, 
2), ROW(3, 4)]), (ARRAY[ROW(5, 6)])))")
+            .returns(1, 2).returns(3, 4).returns(5, 6).check();
+    }
+
+    /** */
+    @Test
+    public void testUnnestMultiCollection() {
+        assertQuery("SELECT * FROM UNNEST(ARRAY[1], ARRAY[2])").returns(1, 
2).check();
+        assertQuery("SELECT * FROM UNNEST(ARRAY[1], ARRAY[2, 3])").returns(1, 
2).returns(1, 3).check();
+
+        assertQuery("SELECT * FROM UNNEST(ARRAY[1, 2, 3], ARRAY[4, 5])")
+            .returns(1, 4).returns(1, 5)
+            .returns(2, 4).returns(2, 5)
+            .returns(3, 4).returns(3, 5)
+            .check();
+
+        assertQuery("SELECT * FROM UNNEST(ARRAY[1, 2, 3], 
?)").withParams(F.asList(4, 5))
+            .returns(1, 4).returns(1, 5)
+            .returns(2, 4).returns(2, 5)
+            .returns(3, 4).returns(3, 5)
+            .check();
+
+        assertQuery("SELECT * FROM UNNEST(ARRAY[1, 2, 3], MAP[4, 5, 6, 7])")
+            .returns(1, 4, 5).returns(1, 6, 7)
+            .returns(2, 4, 5).returns(2, 6, 7)
+            .returns(3, 4, 5).returns(3, 6, 7)
+            .check();
+
+        assertQuery("SELECT * FROM UNNEST(ARRAY[ROW(1, 2), ROW(3, 4)], MAP[5, 
6, 7, 8], ARRAY[9, 10])")
+            .returns(1, 2, 5, 6, 9).returns(1, 2, 5, 6, 10)
+            .returns(1, 2, 7, 8, 9).returns(1, 2, 7, 8, 10)
+            .returns(3, 4, 5, 6, 9).returns(3, 4, 5, 6, 10)
+            .returns(3, 4, 7, 8, 9).returns(3, 4, 7, 8, 10)
+            .check();
+    }
+
+    /** */
+    @Test
+    public void testUnnestMultiLineMultiCollection() {
+        assertQuery("SELECT c, d FROM (VALUES (ARRAY[1, 2], ARRAY[3, 4]), 
(ARRAY[5, 6], ARRAY[7])) v(a, b), " +

Review Comment:
    A Postgres simulator gives that result. Which dialect we use? May be we 
should emphasize it.



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to