beyond1920 commented on a change in pull request #15003: URL: https://github.com/apache/flink/pull/15003#discussion_r584717466
########## File path: flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/runtime/stream/sql/WindowAggregateITCase.scala ########## @@ -101,6 +101,123 @@ class WindowAggregateITCase(mode: StateBackendMode) assertEquals(expected.sorted.mkString("\n"), sink.getAppendResults.sorted.mkString("\n")) } + @Test + def testEventTimeTumbleWindow_GroupingSets(): Unit = { + val sql = + """ + |SELECT + | GROUPING_ID(`name`), + | `name`, + | window_start, + | window_end, + | COUNT(*), + | SUM(`bigdec`), + | MAX(`double`), + | MIN(`float`), + | COUNT(DISTINCT `string`), + | concat_distinct_agg(`string`) + |FROM TABLE( + | TUMBLE(TABLE T1, DESCRIPTOR(rowtime), INTERVAL '5' SECOND)) + |GROUP BY GROUPING SETS((`name`),()), window_start, window_end + """.stripMargin + + val sink = new TestingAppendSink + tEnv.sqlQuery(sql).toAppendStream[Row].addSink(sink) + env.execute() + + val expected = Seq( + "0,a,2020-10-10T00:00,2020-10-10T00:00:05,4,11.10,5.0,1.0,2,Hi|Comment#1", + "0,a,2020-10-10T00:00:05,2020-10-10T00:00:10,1,3.33,null,3.0,1,Comment#2", + "0,b,2020-10-10T00:00:05,2020-10-10T00:00:10,2,6.66,6.0,3.0,2,Hello|Hi", + "0,b,2020-10-10T00:00:15,2020-10-10T00:00:20,1,4.44,4.0,4.0,1,Hi", + "0,b,2020-10-10T00:00:30,2020-10-10T00:00:35,1,3.33,3.0,3.0,1,Comment#3", + "0,null,2020-10-10T00:00:30,2020-10-10T00:00:35,1,7.77,7.0,7.0,0,null", + "1,null,2020-10-10T00:00,2020-10-10T00:00:05,4,11.10,5.0,1.0,2,Hi|Comment#1", + "1,null,2020-10-10T00:00:05,2020-10-10T00:00:10,3,9.99,6.0,3.0,3,Hello|Hi|Comment#2", + "1,null,2020-10-10T00:00:15,2020-10-10T00:00:20,1,4.44,4.0,4.0,1,Hi", + "1,null,2020-10-10T00:00:30,2020-10-10T00:00:35,2,11.10,7.0,3.0,1,Comment#3" + ) + assertEquals(expected.sorted.mkString("\n"), sink.getAppendResults.sorted.mkString("\n")) + } + + @Test + def testEventTimeTumbleWindow_Cube(): Unit = { + val sql = + """ + |SELECT + | GROUPING_ID(`name`), + | `name`, + | window_start, + | window_end, + | COUNT(*), + | SUM(`bigdec`), + | MAX(`double`), + | MIN(`float`), + | COUNT(DISTINCT `string`), + | concat_distinct_agg(`string`) + |FROM TABLE( + | TUMBLE(TABLE T1, DESCRIPTOR(rowtime), INTERVAL '5' SECOND)) + |GROUP BY CUBE(`name`), window_start, window_end + """.stripMargin + + val sink = new TestingAppendSink + tEnv.sqlQuery(sql).toAppendStream[Row].addSink(sink) + env.execute() + + val expected = Seq( + "0,a,2020-10-10T00:00,2020-10-10T00:00:05,4,11.10,5.0,1.0,2,Hi|Comment#1", + "0,a,2020-10-10T00:00:05,2020-10-10T00:00:10,1,3.33,null,3.0,1,Comment#2", + "0,b,2020-10-10T00:00:05,2020-10-10T00:00:10,2,6.66,6.0,3.0,2,Hello|Hi", + "0,b,2020-10-10T00:00:15,2020-10-10T00:00:20,1,4.44,4.0,4.0,1,Hi", + "0,b,2020-10-10T00:00:30,2020-10-10T00:00:35,1,3.33,3.0,3.0,1,Comment#3", + "0,null,2020-10-10T00:00:30,2020-10-10T00:00:35,1,7.77,7.0,7.0,0,null", + "1,null,2020-10-10T00:00,2020-10-10T00:00:05,4,11.10,5.0,1.0,2,Hi|Comment#1", + "1,null,2020-10-10T00:00:05,2020-10-10T00:00:10,3,9.99,6.0,3.0,3,Hello|Hi|Comment#2", + "1,null,2020-10-10T00:00:15,2020-10-10T00:00:20,1,4.44,4.0,4.0,1,Hi", + "1,null,2020-10-10T00:00:30,2020-10-10T00:00:35,2,11.10,7.0,3.0,1,Comment#3" Review comment: done ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org