gustavodemorais commented on code in PR #26113:
URL: https://github.com/apache/flink/pull/26113#discussion_r1957126373
##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/batch/sql/UnnestITCase.scala:
##########
@@ -315,4 +315,279 @@ class UnnestITCase extends BatchTestBase {
Seq(row('a', 1), row('a', 2), row('a', 3)))
}
+ @Test
+ def testUnnestWithOrdinalityWithValuesStream(): Unit = {
+ checkResult(
+ "SELECT * FROM (VALUES('a')) CROSS JOIN UNNEST(ARRAY[1, 2, 3]) WITH
ORDINALITY",
+ Seq(row('a', 1, 1), row('a', 2, 2), row('a', 3, 3))
+ )
+ }
+
+ @Test
+ def testUnnestArrayWithOrdinality(): Unit = {
+ val data = List(
+ row(1, Array(12, 45)),
+ row(2, Array(41, 5)),
+ row(3, Array(18, 42))
+ )
+ registerCollection(
+ "T",
+ data,
+ new RowTypeInfo(Types.INT, Types.PRIMITIVE_ARRAY(Types.INT)),
+ "a, b")
+
+ checkResult(
+ """
+ |SELECT a, number, ordinality
+ |FROM T CROSS JOIN UNNEST(b) WITH ORDINALITY AS t(number, ordinality)
+ |""".stripMargin,
+ Seq(row(1, 12, 1), row(1, 45, 2), row(2, 41, 1), row(2, 5, 2), row(3,
18, 1), row(3, 42, 2))
+ )
+ }
+
+ @Test
+ def testUnnestFromTableWithOrdinality(): Unit = {
+ val data = List(
+ row(1, 1L, Array("Hi", "w")),
+ row(2, 2L, Array("Hello", "k")),
+ row(3, 2L, Array("Hello world", "x"))
+ )
+ registerCollection(
+ "T",
+ data,
+ new RowTypeInfo(Types.INT, Types.LONG, Types.OBJECT_ARRAY(Types.STRING)),
+ "a, b, c")
+
+ checkResult(
+ "SELECT a, s, o FROM T, UNNEST(T.c) WITH ORDINALITY as A (s, o)",
+ Seq(
+ row(1, "Hi", 1),
+ row(1, "w", 2),
+ row(2, "Hello", 1),
+ row(2, "k", 2),
+ row(3, "Hello world", 1),
+ row(3, "x", 2))
+ )
+ }
+
+ @Test
+ def testUnnestArrayOfArrayWithOrdinality(): Unit = {
+ val data = List(
+ row(1, Array(Array(1, 2), Array(3))),
+ row(2, Array(Array(4, 5), Array(6, 7))),
+ row(3, Array(Array(8)))
+ )
+ registerCollection(
+ "T",
+ data,
+ new RowTypeInfo(Types.INT,
Types.OBJECT_ARRAY(Types.PRIMITIVE_ARRAY(Types.INT))),
+ "id, nested_array")
+
+ checkResult(
+ """
+ |SELECT id, array_val, array_pos, `element`, element_pos
+ |FROM T
+ |CROSS JOIN UNNEST(nested_array) WITH ORDINALITY AS A(array_val,
array_pos)
+ |CROSS JOIN UNNEST(array_val) WITH ORDINALITY AS B(`element`,
element_pos)
+ |""".stripMargin,
+ Seq(
+ row(1, Array(1, 2), 1, 1, 1),
+ row(1, Array(1, 2), 1, 2, 2),
+ row(1, Array(3), 2, 3, 1),
+ row(2, Array(4, 5), 1, 4, 1),
+ row(2, Array(4, 5), 1, 5, 2),
+ row(2, Array(6, 7), 2, 6, 1),
+ row(2, Array(6, 7), 2, 7, 2),
+ row(3, Array(8), 1, 8, 1)
+ )
+ )
+ }
+
+ @Test
+ def testUnnestMultisetWithOrdinality(): Unit = {
+ val data = List(
+ row(1, 1, "Hi"),
+ row(1, 2, "Hello"),
+ row(2, 2, "World"),
+ row(3, 3, "Hello world")
+ )
+ registerCollection("T", data, new RowTypeInfo(Types.INT, Types.INT,
Types.STRING), "a, b, c")
+
+ checkResult(
+ """
+ |WITH T1 AS (SELECT a, COLLECT(c) as words FROM T GROUP BY a)
+ |SELECT a, word, pos
+ |FROM T1 CROSS JOIN UNNEST(words) WITH ORDINALITY AS A(word, pos)
+ |""".stripMargin,
+ Seq(row(1, "Hi", 1), row(1, "Hello", 2), row(2, "World", 1), row(3,
"Hello world", 1))
+ )
+ }
+
+ @Test
+ def testUnnestMapWithOrdinality(): Unit = {
+ val data = List(
+ row(1, Map("a" -> "10", "b" -> "11").asJava),
+ row(2, Map("c" -> "20", "d" -> "21").asJava)
+ )
+ registerCollection(
+ "T",
+ data,
+ new RowTypeInfo(Types.INT, Types.MAP(Types.STRING, Types.STRING)),
+ "id, map_data")
+
+ checkResult(
+ """
+ |SELECT id, k, v
+ |FROM T CROSS JOIN UNNEST(map_data) WITH ORDINALITY AS f(k, v, pos)
+ |""".stripMargin,
+ Seq(row(1, "a", "10"), row(1, "b", "11"), row(2, "c", "20"), row(2, "d",
"21"))
+ )
+ }
+
+ @Test
+ def testUnnestForMapOfRowsWithOrdinality(): Unit = {
+ val data = List(
+ row(
+ 1, {
+ val map = new java.util.HashMap[Row, Row]()
Review Comment:
Ops, done. I think this was the only place where I didn't use asJava. See
https://github.com/apache/flink/pull/26113/commits/8d964daf07e8f71637f5d9fb9371342e582a6bd5
--
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]