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

 ##########
 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"
+          + "from table(\"s\".\"generate\"(1, cast(null as integer)))";
+      try {
+        connection.createStatement().executeQuery(sql3);
+      } catch (Exception e) {
+        // org.apache.calcite.runtime.Enumerables.slice0(null)
+        assertThat(e.getCause().toString(),
+            containsString("java.lang.NullPointerException"));
 
 Review comment:
   There might be 100 different NPE flavours.
   Please add a clarification message that would provide human-readable 
description of why NPE was expected.
   
   Otherwise, it would be hard to maintain the test in the future.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to