sunjincheng121 commented on a change in pull request #7235: [FLINK-10976] 
[table] Add support for aggregate to table API
URL: https://github.com/apache/flink/pull/7235#discussion_r244677413
 
 

 ##########
 File path: 
flink-libraries/flink-table/src/test/scala/org/apache/flink/table/api/stream/table/validation/AggregateValidationTest.scala
 ##########
 @@ -47,4 +47,66 @@ class AggregateValidationTest extends TableTestBase {
       // must fail. 'c is not a grouping key or aggregation
       .select('c)
   }
+
+  @Test(expected = classOf[ValidationException])
+  def testAggregationInSelection(): Unit = {
+    val util = streamTestUtil()
+    val table = util.addTable[(Long, Int, String)]('a, 'b, 'c)
+
+    table
+      .groupBy('a)
+      .aggregate('b.sum as 'd)
+      // must fail. Cannot use AggregateFunction in select after aggregate
+      .select('d.sum)
+  }
+
+  @Test(expected = classOf[ValidationException])
+  def testTableFunctionInSelection(): Unit = {
+    val util = streamTestUtil()
+    val table = util.addTable[(Long, Int, String)]('a, 'b, 'c)
+
+    util.tableEnv.registerFunction("func", new TableFunc0)
+    table
+      .groupBy('a)
+      .aggregate('b.sum as 'd)
+      // must fail. Cannot use TableFunction in select after aggregate
+      .select("func(a)")
+  }
+
+  @Test(expected = classOf[ValidationException])
+  def testInvalidExpressionInAggregate(): Unit = {
+    val util = streamTestUtil()
+    val table = util.addTable[(Long, Int, String)]('a, 'b, 'c)
+
+    table
+      .groupBy('a)
+      // must fail. Only AggregateFunction can be used in aggregate
+      .aggregate('b.log as 'd)
+      .select('a, 'd)
+  }
+
+  @Test(expected = classOf[ValidationException])
+  def testInvalidExpressionInAggregate2(): Unit = {
+    val util = streamTestUtil()
+    val table = util.addTable[(Long, Int, String)]('a, 'b, 'c)
+
+    util.tableEnv.registerFunction("func", new TableFunc0)
+    table
+      .groupBy('a)
+      // must fail. Only AggregateFunction can be used in aggregate
+      .aggregate("func(c) as d")
+      .select('a, 'd)
+  }
+
+  @Test(expected = classOf[ExpressionParserException])
+  def testMultipleAggregateExpressionInAggregate(): Unit = {
+    val util = streamTestUtil()
+    val table = util.addTable[(Long, Int, String)]('a, 'b, 'c)
+
+    util.tableEnv.registerFunction("func", new TableFunc0)
 
 Review comment:
   Do you want test tableFunction in select ?
   If not please remove this line.
   if so, please add using the tvf in select.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to