[email protected] has uploaded this change for review. ( 
https://gerrit.cloudera.org/25265


Change subject: IMPALA-15691: Fix INVALID_TYPE error for NULL predicates
......................................................................

IMPALA-15691: Fix INVALID_TYPE error for NULL predicates

With the Calcite planner, IS [NOT] NULL on a NULL-typed operand fails
during planning. For example:
    SELECT a.id, a.int_col, a.string_col
    FROM functional_parquet.alltypessmall a
    WHERE NULL NOT IN (SELECT null);
fails with:
    RuntimeException: Unknown type INVALID_TYPE

There is no is_null_pred(NULL) builtin, so during type coercion
FunctionUtils.resolveFunction() finds every is_null_pred overload an
equally good match and picks the first one. FunctionResolutionOrder
sorts overloads by the getPrimitiveType().ordinal() of their argument
types. VariantType does not override getPrimitiveType(), so it inherits
the Type implementation, which returns INVALID_TYPE. INVALID_TYPE is
the first PrimitiveType, so is_null_pred(VARIANT) sorts first and is
chosen. Casting the NULL operand to VARIANT then fails.

This is a regression from IMPALA-15371, which added the VARIANT
overloads of is_null_pred and is_not_null_pred. The original planner
is not affected because it casts a NULL operand to BOOLEAN before
resolving the function.

Change FunctionResolutionOrder.typeCompare() to rank VARIANT after all
other types, so a NULL operand resolves to is_null_pred(BOOLEAN) again.

Testing:
- Added "select null in (select null)" to calcite.test.
- Ran FE, BE and EE tests.

Change-Id: I284d6750894f3da3379245a648cd01fe6ae60a1b
---
M fe/src/main/java/org/apache/impala/util/FunctionUtils.java
M 
java/calcite-planner/src/main/java/org/apache/impala/calcite/functions/FunctionResolver.java
2 files changed, 12 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/65/25265/1
--
To view, visit https://gerrit.cloudera.org/25265
To unsubscribe, visit https://gerrit.cloudera.org/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I284d6750894f3da3379245a648cd01fe6ae60a1b
Gerrit-Change-Number: 25265
Gerrit-PatchSet: 1
Gerrit-Owner: Anonymous Coward <[email protected]>

Reply via email to