You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2019/09/06 22:51:00 UTC

[jira] [Created] (CALCITE-3326) SQL with invalid function throws NullPointerException if typeCoercion is disabled

Julian Hyde created CALCITE-3326:
------------------------------------

             Summary: SQL with invalid function throws NullPointerException if typeCoercion is disabled
                 Key: CALCITE-3326
                 URL: https://issues.apache.org/jira/browse/CALCITE-3326
             Project: Calcite
          Issue Type: Bug
    Affects Versions: 1.21.0
            Reporter: Julian Hyde


If you have a SQL query with a function that does not exist, and if typeCoercion is disabled, the validator throws a NullPointerException; it should throw a validation exception, same as if typeCoercion is enabled.

Here is a testcase:
{noformat}
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index 43621a7d6..227cc28e9 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -1361,6 +1361,8 @@ public void _testLikeAndSimilarFails() {
 
   @Test public void testInvalidFunction() {
     checkWholeExpFails("foo()", "No match found for function signature FOO..");
+    checkFails("select foo()", "No match found for function signature FOO..",
+        false);
     checkWholeExpFails("mod(123)",
         "Invalid number of arguments to function 'MOD'. Was expecting 2 arguments");
   }
{noformat}
throws
{noformat}
	at java.base/java.util.Objects.requireNonNull(Objects.java:221)
	at org.apache.calcite.sql.SqlBasicCall.setOperator(SqlBasicCall.java:67)
	at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:297)
	at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:216)
	at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5626)
{noformat}

It's clear that the flow at [SqlFunction line 274|https://github.com/apache/calcite/blob/955d4ea7b30b85519529c1c77662fa04141bfa89/core/src/main/java/org/apache/calcite/sql/SqlFunction.java#L274] will let through {{function = null}} if coercion is disabled. This was caused by CALCITE-2302.

Are there other possible paths through that block where {{function}} ends up null at the end? It's not clear from looking at the code.

[~danny0405], Can you please take a look? Cc: [~fib-seq].



--
This message was sent by Atlassian Jira
(v8.3.2#803003)