You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by wz...@apache.org on 2021/11/11 07:43:19 UTC

[impala] 03/03: IMPALA-11011: Impala crashes in OrcStructReader::NumElements()

This is an automated email from the ASF dual-hosted git repository.

wzhou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit cb0018e679f4b48e98d20590679bcd157ef36ee2
Author: Daniel Becker <da...@cloudera.com>
AuthorDate: Tue Nov 9 17:21:06 2021 +0100

    IMPALA-11011: Impala crashes in OrcStructReader::NumElements()
    
    Running the query
    
    select inner_arr.ITEM
    from functional_orc_def.complextypestbl_non_transactional.nested_struct.c.d.ITEM
    as inner_arr;
    
    crashes Impala because in OrcStructReader::NumElements() 'vbatch_' is
    NULL and we dereference it.
    
    This commit adds a NULL check and if 'vbatch_' is NULL, NumElements()
    returns 0.
    
    Testing:
      - added a regression test in
        'testdata/workloads/functional-query/queries/QueryTest/struct-in-select-list.test'
        that runs the above query.
    
    Change-Id: I19cea7afdd1b3542a20a81b9f212fa320f3c1427
    Reviewed-on: http://gerrit.cloudera.org:8080/18007
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 be/src/exec/orc-column-readers.h                    |  4 +++-
 .../queries/QueryTest/struct-in-select-list.test    | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/be/src/exec/orc-column-readers.h b/be/src/exec/orc-column-readers.h
index ea87c6a..2dd5663 100644
--- a/be/src/exec/orc-column-readers.h
+++ b/be/src/exec/orc-column-readers.h
@@ -600,7 +600,9 @@ class OrcStructReader : public OrcComplexColumnReader {
   int GetChildBatchOffset(int row_idx) const override { return row_idx; }
 
   int NumElements() const final {
-    if (MaterializeTuple()) return vbatch_->numElements;
+    if (MaterializeTuple()) {
+      return vbatch_ ? vbatch_->numElements : 0;
+    }
     DCHECK_EQ(children().size(), 1);
     OrcColumnReader* child = children()[0];
     return child->NumElements();
diff --git a/testdata/workloads/functional-query/queries/QueryTest/struct-in-select-list.test b/testdata/workloads/functional-query/queries/QueryTest/struct-in-select-list.test
index 4e9327a..ec290c8 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/struct-in-select-list.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/struct-in-select-list.test
@@ -288,6 +288,27 @@ from functional_orc_def.complextypestbl.nested_struct.c.d.ITEM as inner_arr;
 STRING,INT,STRING
 ====
 ---- QUERY
+# Similar to the above, but on a non-transactional version of the table.
+# Regression test for IMPALA-11011.
+select inner_arr.ITEM
+from functional_orc_def.complextypestbl_non_transactional.nested_struct.c.d.ITEM as inner_arr;
+---- RESULTS
+'{"e":-1,"f":"nonnullable"}'
+'{"e":10,"f":"aaa"}'
+'{"e":-10,"f":"bbb"}'
+'{"e":11,"f":"c"}'
+'{"e":null,"f":null}'
+'{"e":10,"f":"aaa"}'
+'{"e":null,"f":null}'
+'{"e":-10,"f":"bbb"}'
+'{"e":null,"f":null}'
+'{"e":11,"f":"c"}'
+'NULL'
+'NULL'
+---- TYPES
+STRING
+====
+---- QUERY
 # Querying a struct that is inside a nested array. Referencing the inner array through a
 # join with the base table.
 select tbl.id, inner_arr.ITEM