Jason Fehr has submitted this change and it was merged. ( 
https://gerrit.cloudera.org/25226 )

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: Id06b23cb958566a5a90cc321fe215d8c2a634b71
Reviewed-on: https://gerrit.cloudera.org/25226
Reviewed-by: Joe McDonnell <[email protected]>
Reviewed-by: Steve Carlin <[email protected]>
Tested-by: Impala Public Jenkins <[email protected]>
---
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
M testdata/workloads/functional-query/queries/QueryTest/calcite.test
3 files changed, 31 insertions(+), 3 deletions(-)

Approvals:
  Joe McDonnell: Looks good to me, but someone else must approve
  Steve Carlin: Looks good to me, approved
  Impala Public Jenkins: Verified

--
To view, visit https://gerrit.cloudera.org/25226
To unsubscribe, visit https://gerrit.cloudera.org/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Id06b23cb958566a5a90cc321fe215d8c2a634b71
Gerrit-Change-Number: 25226
Gerrit-PatchSet: 5
Gerrit-Owner: Wellington Cabrera <[email protected]>
Gerrit-Reviewer: Impala Public Jenkins <[email protected]>
Gerrit-Reviewer: Jason Fehr <[email protected]>
Gerrit-Reviewer: Joe McDonnell <[email protected]>
Gerrit-Reviewer: Steve Carlin <[email protected]>
Gerrit-Reviewer: Wellington Cabrera <[email protected]>
Gerrit-Reviewer: Zoltan Borok-Nagy <[email protected]>

Reply via email to