beyond1920 commented on code in PR #2844:
URL: https://github.com/apache/calcite/pull/2844#discussion_r915788510


##########
core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java:
##########
@@ -1564,6 +1564,50 @@ public void _testLikeAndSimilarFails() {
         .fails("No match found for function signature FOO..");
   }
 
+  @Test void testInvalidTableFunction() {
+    // A table function at most have one input table with row semantics
+    sql("select * from table(^invalid(table orders, table emp)^)")
+        .fails("A table function at most has one input table with row 
semantics."
+            + " Table function 'INVALID' has multiple input tables with row 
semantics");
+    // Only tables with set semantics may be partitioned
+    sql("select * from table(^score(table orders partition by productid)^)")
+        .fails("Only tables with set semantics may be partitioned."
+            + " Invalid PARTITION BY clause in the 0-th operand of table 
function 'SCORE'");
+    // Only tables with set semantics may be ordered

Review Comment:
   > We need some tests for multiple partition/ordering keys.
   
   There are already exist cases to cover these in 
SqlValidatorTest#testTableFunctionWithTableParam.
   
   > We need some tests for multiple table params.
   
   Based on SQL standard, a table function at most has one input table with row 
semantics, there are already exist cases to cover these based on 
MockSqlOperatorTable#InvalidTableFunction.
   
   I add some cases to cover a table function with multiple input tables with 
set semantics based on MockSqlOperatorTable#SimilarlityTableFunction.



##########
testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java:
##########
@@ -4164,6 +4164,77 @@ void checkPeriodPredicate(Checker checker) {
     sql(sql).ok(expected);
   }
 
+  @Test void testTableFunction() {
+    final String sql = "select * from table(score(table orders))";
+    final String expected = "SELECT *\n"
+        + "FROM TABLE(`SCORE`((TABLE `ORDERS`)))";
+    sql(sql).ok(expected);
+  }
+
+  @Test void testTableFunctionWithPartitionKey() {
+    // test one partition key for input table
+    final String sql = "select * from table(topn(table orders partition by 
productid, 3))";
+    final String expected = "SELECT *\n"
+        + "FROM TABLE(`TOPN`(((TABLE `ORDERS`) PARTITION BY `PRODUCTID`), 3))";
+    sql(sql).ok(expected);
+  }
+
+  @Test void testTableFunctionWithMultiplePartitionKeys() {
+    // test multiple partition keys for input table
+    final String sql =
+        "select * from table(topn(table orders partition by (orderId, 
productid), 3))";
+    final String expected = "SELECT *\n"
+        + "FROM TABLE(`TOPN`(((TABLE `ORDERS`) PARTITION BY `ORDERID`, 
`PRODUCTID`), 3))";
+    sql(sql).ok(expected);
+  }

Review Comment:
   > We need some tests for multiple partition/ordering keys.
   
   There are already exist cases to cover these, for example, 
SqlParserTest#testTableFunctionWithMultiplePartitionKeys, 
SqlParserTest#testTableFunctionWithMultipleOrderKeys
   
   
   > We need some tests for multiple table params.
   
   Based on SQL standard, a table function at most has one input table with row 
semantics, there are already exist cases to cover these based on 
MockSqlOperatorTable#InvalidTableFunction.
   
   I add some cases to cover a table function with multiple input tables with 
set semantics based on MockSqlOperatorTable#SimilarlityTableFunction.



-- 
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