DonnyZone commented on a change in pull request #1593: [CALCITE-3513] Unify 
TableFunction implementor's NullPolicy and its behavior
URL: https://github.com/apache/calcite/pull/1593#discussion_r351069104
 
 

 ##########
 File path: core/src/test/java/org/apache/calcite/test/TableFunctionTest.java
 ##########
 @@ -487,6 +487,47 @@ private Connection getConnectionWithMultiplyFunction() 
throws SQLException {
       assertThat(CalciteAssert.toString(resultSet), equalTo(expected));
     }
   }
+
+  /**
+   * Test of a table function that produces null.
+   */
+  @Test public void testNullContentTableFunction() throws SQLException {
+    try (Connection connection = DriverManager.getConnection("jdbc:calcite:")) 
{
+      CalciteConnection calciteConnection =
+          connection.unwrap(CalciteConnection.class);
+      SchemaPlus rootSchema = calciteConnection.getRootSchema();
+      SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
+      final TableFunction table =
+          TableFunctionImpl.create(Smalls.NULL_PRODUCED_METHOD);
+      schema.add("generate", table);
+
+      final String sql1 = "select *\n"
+          + "from table(\"s\".\"generate\"(1, 2))";
+      ResultSet resultSet = connection.createStatement().executeQuery(sql1);
+      final String expected1 = "S=abcde\n"
+          + "S=xyz\n"
+          + "S=generate(x=1, y=2)\n";
+      assertThat(CalciteAssert.toString(resultSet), equalTo(expected1));
+
+      final String sql2 = "select *\n"
+          + "from table(\"s\".\"generate\"(1, 1))";
+      resultSet = connection.createStatement().executeQuery(sql2);
+      final String expected2 =  "S=abcde\n"
+          + "S=xyz\n"
+          + "S=null\n";
+      assertThat(CalciteAssert.toString(resultSet), equalTo(expected2));
+
+      final String sql3 = "select *\n"
 
 Review comment:
   NPE is produced by annotation (`strict`), it prevent the `null` arguments to 
enter the function and directly return `null` result.
   I intend to show that it seems not reasonable to allow users to declare 
annotations for `TableFunction`s.

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


With regards,
Apache Git Services

Reply via email to