Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-3326

SQL with invalid function throws NullPointerException if typeCoercion is disabled

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.21.0
    • Fix Version/s: 1.22.0
    • Component/s: None
    • Labels:
      None

      Description

      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:

      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");
         }
      

      throws

      	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)
      

      It's clear that the flow at SqlFunction line 274 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.

      Danny Chen, Can you please take a look? Cc: Ryan Fu.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                danny0405 Danny Chen
                Reporter:
                julianhyde Julian Hyde
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: