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
The following commit(s) were added to refs/heads/master by this push:
new ed59690b4 IMPALA-11840: Error with joining unnest with views
ed59690b4 is described below
commit ed59690b4480ff332edef1ccb2456385ac52220b
Author: Daniel Becker <[email protected]>
AuthorDate: Tue Jan 17 11:54:11 2023 +0100
IMPALA-11840: Error with joining unnest with views
Queries fail in the following situation involving collections and views:
1. A view returns an array
2. A second view unnests the array returned from the first view
3. The unnested view is queried in an outer query
For example:
use functional_parquet;
with sub as (
select id, arr1.item unnested_arr
from complextypes_arrays_only_view,
complextypes_arrays_only_view.int_array arr1)
select id, unnested_arr from sub;
ERROR: IllegalStateException: null
The problem is that in CollectionTableRef.analyze(), if
- there is a source view and
- the collection ref is within a WITH clause and
- it is not in the select list
then 'desc_' is not set, but it has to be set in order for
TableRef.analyzeJoin() to succeed.
This commit solves the problem by assigning a value to 'desc_' also in
the above case.
Testing:
- Added regression tests in nested-types-runtime.test.
Change-Id: Ic52655631944913553a7e7d9e9169b93da46dde3
Reviewed-on: http://gerrit.cloudera.org:8080/19426
Reviewed-by: Impala Public Jenkins <[email protected]>
Tested-by: Impala Public Jenkins <[email protected]>
---
.../apache/impala/analysis/CollectionTableRef.java | 41 ++++++-----
.../queries/QueryTest/nested-types-runtime.test | 82 ++++++++++++++++++++++
2 files changed, 104 insertions(+), 19 deletions(-)
diff --git
a/fe/src/main/java/org/apache/impala/analysis/CollectionTableRef.java
b/fe/src/main/java/org/apache/impala/analysis/CollectionTableRef.java
index 521a4bb09..2656886d5 100644
--- a/fe/src/main/java/org/apache/impala/analysis/CollectionTableRef.java
+++ b/fe/src/main/java/org/apache/impala/analysis/CollectionTableRef.java
@@ -121,26 +121,29 @@ public class CollectionTableRef extends TableRef {
"supported on collections from views.");
}
+ if (isRelative() && sourceView != null && !inSelectList_) {
+ // The collection is a column from a view. This means that we must reuse
the
+ // existing tuple desc created by the view. This is not needed when the
+ // collection is in a select list, as the slot refs in the select list
are
+ // substituted in SelectStmt.resolveInlineViewRefs()
+ // TODO: currently we cannot use the same array twice (e.g. self join)
in this
+ // case
+ SlotDescriptor parentSlotDesc = analyzer.getSlotDescriptor(
+ resolvedPath_.getFullyQualifiedRawPath());
+ collectionExpr_ = new SlotRef(parentSlotDesc);
+ collectionExpr_ =
+ collectionExpr_.trySubstitute(sourceView.getBaseTblSmap(), analyzer,
true);
+ desc_ = ((SlotRef) collectionExpr_).getDesc().getItemTupleDesc();
+ // The tuple desc was hidden as it belonged to a collection in select
list in
+ // a view. Set hidden to false, as now it is in the from clause.
+ Preconditions.checkState(desc_.isHidden());
+ desc_.setHidden(false);
+
+ analyzer.addCollectionTableRef(getUniqueAlias(), this, desc_);
+ }
+
if (isRelative() && (!analyzer.hasWithClause() || inSelectList_)) {
- if (sourceView != null && !inSelectList_) {
- // The collection is a column from a view. This means that we must
reuse the
- // existing tuple desc created by the view. This is not needed when the
- // collection is in a select list, as the slot refs in the select list
are
- // substituted in SelectStmt.resolveInlineViewRefs()
- // TODO: currently we cannot use the same array twice (e.g. self join)
in this
- // case
- SlotDescriptor parentSlotDesc = analyzer.getSlotDescriptor(
- resolvedPath_.getFullyQualifiedRawPath());
- collectionExpr_ = new SlotRef(parentSlotDesc);
- collectionExpr_ =
- collectionExpr_.trySubstitute(sourceView.getBaseTblSmap(),
analyzer, true);
- desc_ = ((SlotRef) collectionExpr_).getDesc().getItemTupleDesc();
- // The tuple desc was hidden as it belonged to a collection in select
list in
- // a view. Set hidden to false, as now it is in the from clause.
- Preconditions.checkState(desc_.isHidden());
- desc_.setHidden(false);
- analyzer.addCollectionTableRef(getUniqueAlias(), this, desc_);
- } else {
+ if (sourceView == null || inSelectList_) {
SlotDescriptor parentSlotDesc =
analyzer.registerSlotRef(resolvedPath_);
parentSlotDesc.setItemTupleDesc(desc_);
collectionExpr_ = new SlotRef(parentSlotDesc);
diff --git
a/testdata/workloads/functional-query/queries/QueryTest/nested-types-runtime.test
b/testdata/workloads/functional-query/queries/QueryTest/nested-types-runtime.test
index 343d5a48a..658f4b68d 100644
---
a/testdata/workloads/functional-query/queries/QueryTest/nested-types-runtime.test
+++
b/testdata/workloads/functional-query/queries/QueryTest/nested-types-runtime.test
@@ -514,3 +514,85 @@ where length(e.key) > 0
---- TYPES
BIGINT,STRING
====
+---- QUERY
+# Regression test for IMPALA-11840. Array coming from view and unnested in
WITH clause.
+with sub as (
+ select id, arr1.item unnested_arr
+ from complextypes_arrays_only_view,
complextypes_arrays_only_view.int_array_array arr1)
+select id, unnested_arr from sub;
+---- RESULTS
+1,'[1,2]'
+1,'[3,4]'
+2,'[null,1,2,null]'
+2,'[3,null,4]'
+2,'[]'
+2,'NULL'
+3,'NULL'
+7,'NULL'
+7,'[5,6]'
+8,'[-1,-2]'
+8,'[]'
+---- TYPES
+BIGINT,STRING
+====
+---- QUERY
+# Regression test for IMPALA-11840. Using nested query instead of WITH clause,
should
+# produce the same result.
+select id, unnested_arr from (
+ select id, arr1.item unnested_arr
+ from complextypes_arrays_only_view,
complextypes_arrays_only_view.int_array_array arr1) sub;
+---- RESULTS
+1,'[1,2]'
+1,'[3,4]'
+2,'[null,1,2,null]'
+2,'[3,null,4]'
+2,'[]'
+2,'NULL'
+3,'NULL'
+7,'NULL'
+7,'[5,6]'
+8,'[-1,-2]'
+8,'[]'
+---- TYPES
+BIGINT,STRING
+====
+---- QUERY
+# Regression test for IMPALA-11840. Array coming from view and unnested in
WITH clause.
+with sub as (
+ select id, arr1.item int_arr_item
+ from complextypestbl, complextypestbl.int_array arr1)
+select id, int_arr_item from sub;
+---- RESULTS
+8,-1
+1,1
+1,2
+1,3
+2,NULL
+2,1
+2,2
+2,NULL
+2,3
+2,NULL
+---- TYPES
+BIGINT,INT
+====
+---- QUERY
+# Regression test for IMPALA-11840. Using nested query instead of WITH clause,
should
+# produce the same result.
+select id, int_arr_item from (
+ select id, arr1.item int_arr_item
+ from complextypes_arrays_only_view, complextypes_arrays_only_view.int_array
arr1) sub;
+---- RESULTS
+8,-1
+1,1
+1,2
+1,3
+2,NULL
+2,1
+2,2
+2,NULL
+2,3
+2,NULL
+---- TYPES
+BIGINT,INT
+====