You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by st...@apache.org on 2024/01/16 01:01:25 UTC

(impala) 02/03: IMPALA-12704: Fix NPE when quering empty iceberg table's metadata

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

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

commit ad2e7ff6bce6048ac1ee58c9bfc911fd392d655c
Author: Eyizoha <ey...@163.com>
AuthorDate: Fri Jan 12 10:52:07 2024 +0800

    IMPALA-12704: Fix NPE when quering empty iceberg table's metadata
    
    Currently, When querying some metadata tables of an empty iceberg table,
    a null pointer exception occurs. This patch fixes the issue and adds
    corresponding test cases in test_metadata_tables.
    
    Testing:
     - Added E2E test to cover this case
    
    Change-Id: I6b4d4fb81a45214045b8809a4bdd910a1f1f3843
    Reviewed-on: http://gerrit.cloudera.org:8080/20890
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 .../apache/impala/util/IcebergMetadataScanner.java |  4 +--
 .../queries/QueryTest/iceberg-metadata-tables.test | 35 ++++++++++++++--------
 2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/fe/src/main/java/org/apache/impala/util/IcebergMetadataScanner.java b/fe/src/main/java/org/apache/impala/util/IcebergMetadataScanner.java
index 18f3d8981..37087da43 100644
--- a/fe/src/main/java/org/apache/impala/util/IcebergMetadataScanner.java
+++ b/fe/src/main/java/org/apache/impala/util/IcebergMetadataScanner.java
@@ -102,11 +102,11 @@ public class IcebergMetadataScanner {
    */
   public StructLike GetNext() {
     // Return the next row in the DataRows iterator
-    if (dataRowsIterator_.hasNext()) {
+    if (dataRowsIterator_ != null && dataRowsIterator_.hasNext()) {
       return dataRowsIterator_.next();
     }
     // Otherwise this DataTask is empty, find a FileScanTask that has a non-empty DataTask
-    if(FindFileScanTaskWithRows()) {
+    if (FindFileScanTaskWithRows()) {
       return dataRowsIterator_.next();
     }
     return null;
diff --git a/testdata/workloads/functional-query/queries/QueryTest/iceberg-metadata-tables.test b/testdata/workloads/functional-query/queries/QueryTest/iceberg-metadata-tables.test
index a559e13b6..e678efe9a 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/iceberg-metadata-tables.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/iceberg-metadata-tables.test
@@ -176,7 +176,18 @@ row_regex:1,[1-9]\d*|0,[1-9]\d*|0,[1-9]\d*|0
 INT,BIGINT,BIGINT,BIGINT
 
 ####
-# Test 1 : Test select list
+# Test 1 : Test query empty table's metadata
+####
+====
+---- QUERY
+create table empty_ice_tbl (id int) stored by iceberg;
+select * from $DATABASE.empty_ice_tbl.entries;
+---- RESULTS
+---- TYPES
+INT,BIGINT,BIGINT,BIGINT
+
+####
+# Test 2 : Test select list
 ####
 ====
 ---- QUERY
@@ -218,7 +229,7 @@ select record_count + file_count from functional_parquet.iceberg_query_metadata.
 BIGINT
 
 ####
-# Test 2 : Test filtering
+# Test 3 : Test filtering
 ####
 ====
 ---- QUERY
@@ -285,7 +296,7 @@ row_regex:$OVERWRITE_SNAPSHOT_TS,$OVERWRITE_SNAPSHOT_ID,[1-9]\d*|0,true
 TIMESTAMP,BIGINT,BIGINT,BOOLEAN
 
 ####
-# Test 2 : Test joins
+# Test 4 : Test joins
 ####
 ====
 ---- QUERY
@@ -328,7 +339,7 @@ $OVERWRITE_SNAPSHOT_ID
 BIGINT
 
 ####
-# Test 3 : Inline query
+# Test 5 : Inline query
 ####
 ====
 ---- QUERY
@@ -343,7 +354,7 @@ row_regex:[1-9]\d*|0
 BIGINT
 
 ####
-# Test 4 : Complex types
+# Test 6 : Complex types
 # Currently not supported, complex type slots are set to NULL (IMPALA-12205)
 ####
 ====
@@ -358,7 +369,7 @@ row_regex:[1-9]\d*|0,'NULL'
 BIGINT,STRING
 
 ####
-# Test 5 : Multiple RowBatch results
+# Test 7 : Multiple RowBatch results
 ####
 ====
 ---- QUERY
@@ -372,9 +383,8 @@ row_regex:\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}(\.\d{9})?,[1-9]\d*|0,[1-9]\d*|0,t
 ---- TYPES
 TIMESTAMP,BIGINT,BIGINT,BOOLEAN
 
-
 ####
-# Test 6 : Timetravel
+# Test 8 : Timetravel
 # Timetravel is not supported currently, related Jira IMPALA-11991.
 ####
 ====
@@ -385,7 +395,7 @@ AnalysisException: FOR SYSTEM_VERSION AS OF clause is only supported for Iceberg
 ====
 
 ####
-# Test 7 : Use-cases
+# Test 9 : Use-cases
 ####
 ====
 ---- QUERY
@@ -415,7 +425,7 @@ row_regex:[1-9]\d*|0,'$NAMENODE/test-warehouse/iceberg_test/hadoop_catalog/ice/i
 INT,STRING,BIGINT
 
 ####
-# Test 8 : Invalid operations
+# Test 10 : Invalid operations
 # In most cases the parser catches the table reference.
 ####
 ====
@@ -456,7 +466,7 @@ ParseException: Syntax error in line 1
 ====
 
 ####
-# Test 9 : Query nested type columns
+# Test 11 : Query nested type columns
 ####
 ====
 ---- QUERY
@@ -563,8 +573,9 @@ AnalysisException: Querying collection types (ARRAY/MAP) is not supported for Ic
 ====
 
 ####
-# Test 10 : Describe all the metadata tables once
+# Test 12 : Describe all the metadata tables once
 ####
+====
 ---- QUERY
 describe functional_parquet.iceberg_query_metadata.snapshots;
 ---- RESULTS