Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.21.0
-
None
-
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.
Attachments
Issue Links
- is duplicated by
-
CALCITE-3360 SqlValidator throws NPE for unregistered function without implicit type coercion
- Closed
- relates to
-
CALCITE-2302 Implicit type cast support
- Closed