This is an automated email from the ASF dual-hosted git repository. joemcdonnell pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/impala.git
commit 2e1ce445b24aba7d851475512a4c0378cbae0b4f Author: Csaba Ringhofer <[email protected]> AuthorDate: Thu Sep 8 15:55:46 2022 +0200 IMPALA-11567: Fix left outer join if the right side is subquery with complex type Non-matching rows from the left side will null out all slots from the right side in left outer joins. If the right side is a subquery, it is possible that some returned expressions will be non-NULL even if all slots are NULL (e.g. constants) - these expressions are wrapped as IF(TupleIsNull(tids), NULL, expr) to null them in the non-matching case. The logic above used to hit a precondition for complex types. We can safely ignore complex types for now, as currently the only possible expression that returns a complex type is SlotRef, which doesn't need to be wrapped. We will have to revisit this once functions are added that return complex types. Testing: - added a regression test and ran it Change-Id: Iaa8991cd4448d5c7ef7f44f73ee07e2a2b6f37ce Reviewed-on: http://gerrit.cloudera.org:8080/18954 Reviewed-by: Impala Public Jenkins <[email protected]> Tested-by: Impala Public Jenkins <[email protected]> --- .../org/apache/impala/analysis/TupleIsNullPredicate.java | 10 ++++++++-- .../queries/QueryTest/nested-array-in-select-list.test | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/fe/src/main/java/org/apache/impala/analysis/TupleIsNullPredicate.java b/fe/src/main/java/org/apache/impala/analysis/TupleIsNullPredicate.java index da78e6dc3..92685b8ba 100644 --- a/fe/src/main/java/org/apache/impala/analysis/TupleIsNullPredicate.java +++ b/fe/src/main/java/org/apache/impala/analysis/TupleIsNullPredicate.java @@ -162,8 +162,14 @@ public class TupleIsNullPredicate extends Predicate { public static boolean requiresNullWrapping(Expr expr, Analyzer analyzer) throws InternalException { Preconditions.checkNotNull(expr); - Preconditions.checkState(!expr.getType().isComplexType(), - "Should not evaluate on complex type: " + expr.debugString()); + + if (expr.getType().isComplexType()) { + // Currently the only Expr supported for complex types is SlotRef, which does not + // need NULL wrapping. + Preconditions.checkState(expr instanceof SlotRef); + return false; + } + // If the expr is already wrapped in an IF(TupleIsNull(), NULL, expr) // then it must definitely be wrapped again at this level. // Do not try to execute expr because a TupleIsNullPredicate is not constant. diff --git a/testdata/workloads/functional-query/queries/QueryTest/nested-array-in-select-list.test b/testdata/workloads/functional-query/queries/QueryTest/nested-array-in-select-list.test index 14c1c54d1..f5ef5612d 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/nested-array-in-select-list.test +++ b/testdata/workloads/functional-query/queries/QueryTest/nested-array-in-select-list.test @@ -391,4 +391,18 @@ select id, arr_int_1d, arr_int_2d, arr_int_3d, arr_string_1d, arr_string_2d, arr 1,'[1,2,NULL]','[[1,2,NULL],[3]]','[[[1,2,NULL],[3]],[[4]]]','["1","2",NULL]','[["1","2",NULL],["3"]]','[[["1","2",NULL],["3"]],[["4"]]]' ---- TYPES INT,STRING,STRING,STRING,STRING,STRING,STRING +==== +---- QUERY +# Regression test for: +# IMPALA-11567: "Error in left outer join if the right side is a subquery with complex types" +select a.id, b.arr_int_1d, b.arr_int_2d +from alltypestiny a left outer join + (select id, arr_int_1d, arr_int_2d from collection_tbl) b +on a.id = b.id where a.id < 3; +---- RESULTS +0,'NULL','NULL' +1,'[1,2,NULL]','[[1,2,NULL],[3]]' +2,'NULL','NULL' +---- TYPES +INT,STRING,STRING =====
