You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by bo...@apache.org on 2022/02/23 10:03:34 UTC

[impala] 02/03: IMPALA-11134: Impala returns "Couldn't skip rows in file" error for old Parquet file

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

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

commit b60ccabd5b6f09842284c657b910bb65d2f30fe8
Author: Zoltan Borok-Nagy <bo...@cloudera.com>
AuthorDate: Sat Feb 19 18:21:49 2022 +0100

    IMPALA-11134: Impala returns "Couldn't skip rows in file" error for old Parquet file
    
    Impala returns "Couldn't skip rows in file" error for old Parquet
    file written by an old Impala (e.g. Impala 2.5, 2.6) In DEBUG build
    Impala crashes by a DCHECK:
    
     Check failed: num_buffered_values_ > 0 (-1 vs. 0)
    
    The problem is that in some old Parquet files there can be a mismatch
    between 'num_values' in a page and the encoded def/rep levels.
    There is usually one more def/rep levels encoded in these files.
    
    In SkipTopLevelRows() we skipped values based on how many def levels are
    https://github.com/apache/impala/blob/92ce6fe48e75d7780efe9a275122554e59aac916/be/src/exec/parquet/parquet-column-readers.cc#L1308-L1314
    
    Since there are more def levels than values in some old files,
    num_buferred_values_ could become negative.
    
    This patch also takes the value of num_buferred_values_ into account
    when calculating 'read_count', so we can deal with such files. With
    this patch we also include the column name in the "Couldn't skip rows"
    error message, so in the future it'll be easier to identify the
    problematic columns.
    
    Testing:
     * added Parquet file written by Impala 2.5 and e2e test for it
    
    Change-Id: I568fe59df720ea040be4926812412ba4c1510a26
    Reviewed-on: http://gerrit.cloudera.org:8080/18257
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 be/src/exec/parquet/hdfs-parquet-scanner.cc   |   9 ++++++---
 be/src/exec/parquet/parquet-column-readers.cc |   9 ++++++++-
 common/thrift/generate_error_codes.py         |   2 ++
 testdata/data/README                          |   3 +++
 testdata/data/too_many_def_levels.parquet     | Bin 0 -> 500880 bytes
 tests/query_test/test_scanners.py             |   9 +++++++++
 6 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/be/src/exec/parquet/hdfs-parquet-scanner.cc b/be/src/exec/parquet/hdfs-parquet-scanner.cc
index 87ad679..94f2b6e 100644
--- a/be/src/exec/parquet/hdfs-parquet-scanner.cc
+++ b/be/src/exec/parquet/hdfs-parquet-scanner.cc
@@ -2392,12 +2392,14 @@ Status HdfsParquetScanner::FillScratchMicroBatches(
       if (r == 0) {
         if (micro_batches[0].start > 0) {
           if (UNLIKELY(!col_reader->SkipRows(micro_batches[0].start, -1))) {
-            return Status(Substitute("Couldn't skip rows in file $0.", filename()));
+            return Status(ErrorMsg(TErrorCode::PARQUET_ROWS_SKIPPING,
+                col_reader->schema_element().name, filename()));
           }
         }
       } else {
         if (UNLIKELY(!col_reader->SkipRows(micro_batches[r].start - last - 1, -1))) {
-          return Status(Substitute("Couldn't skip rows in file $0.", filename()));
+          return Status(ErrorMsg(TErrorCode::PARQUET_ROWS_SKIPPING,
+              col_reader->schema_element().name, filename()));
         }
       }
       uint8_t* next_tuple_mem = scratch_batch_->tuple_mem
@@ -2430,7 +2432,8 @@ Status HdfsParquetScanner::FillScratchMicroBatches(
     }
     if (UNLIKELY(last < max_num_tuples - 1)) {
       if (UNLIKELY(!col_reader->SkipRows(max_num_tuples - 1 - last, -1))) {
-        return Status(Substitute("Couldn't skip rows in file $0.", filename()));
+        return Status(ErrorMsg(TErrorCode::PARQUET_ROWS_SKIPPING,
+            col_reader->schema_element().name, filename()));
       }
     }
   }
diff --git a/be/src/exec/parquet/parquet-column-readers.cc b/be/src/exec/parquet/parquet-column-readers.cc
index 3a8ac36..70e736e 100644
--- a/be/src/exec/parquet/parquet-column-readers.cc
+++ b/be/src/exec/parquet/parquet-column-readers.cc
@@ -1270,7 +1270,8 @@ Status BaseScalarColumnReader::StartPageFiltering() {
     int64_t skip_rows = range_start - current_row_ - 1;
     int64_t remaining = 0;
     if (!SkipTopLevelRows(skip_rows, &remaining)) {
-      return Status(Substitute("Couldn't skip rows in file $0.", filename()));
+      return Status(ErrorMsg(TErrorCode::PARQUET_ROWS_SKIPPING,
+          schema_element().name, filename()));
     }
     DCHECK_EQ(remaining, 0);
     DCHECK_EQ(current_row_, range_start - 1);
@@ -1308,12 +1309,18 @@ bool BaseScalarColumnReader::SkipTopLevelRows(int64_t num_rows, int64_t* remaini
       int repeated_run_length = def_levels_.NextRepeatedRunLength();
       if (repeated_run_length > 0) {
         int read_count = min<int64_t>(num_rows - i, repeated_run_length);
+        // IMPALA-11134: there can be a mismatch between page_header.num_values and
+        // encoded def levels in old Parquet files.
+        read_count = min(num_buffered_values_, read_count);
         int16_t def_level = def_levels_.GetRepeatedValue(read_count);
         if (def_level >= max_def_level_) num_values_to_skip += read_count;
         i += read_count;
         num_buffered_values_ -= read_count;
       } else if (def_levels_.CacheHasNext()) {
         int read_count = min<int64_t>(num_rows - i, def_levels_.CacheRemaining());
+        // IMPALA-11134: there can be a mismatch between page_header.num_values and
+        // encoded def levels in old Parquet files.
+        read_count = min(num_buffered_values_, read_count);
         for (int j = 0; j < read_count; ++j) {
           if (def_levels_.CacheGetNext() >= max_def_level_) ++num_values_to_skip;
         }
diff --git a/common/thrift/generate_error_codes.py b/common/thrift/generate_error_codes.py
index b4751c8..23e08a8 100755
--- a/common/thrift/generate_error_codes.py
+++ b/common/thrift/generate_error_codes.py
@@ -475,6 +475,8 @@ error_codes = (
   ("JWKS_PARSE_ERROR", 153, "Error parsing JWKS: $0."),
 
   ("JWT_VERIFY_FAILED", 154, "Error verifying JWT Token: $0."),
+
+  ("PARQUET_ROWS_SKIPPING", 155, "Couldn't skip rows in column '$0' in file '$1'."),
 )
 
 import sys
diff --git a/testdata/data/README b/testdata/data/README
index bfaa0c1..f687034 100644
--- a/testdata/data/README
+++ b/testdata/data/README
@@ -675,3 +675,6 @@ field ids.
 iceberg_test/hadoop_catalog/ice/airports_orc:
 Regular ORC table converted to Iceberg, which means that the data file doesn't contain
 field ids.
+
+too_many_def_levels.parquet:
+Written by Impala 2.5. The Parquet pages have more encoded def levels than num_values.
diff --git a/testdata/data/too_many_def_levels.parquet b/testdata/data/too_many_def_levels.parquet
new file mode 100644
index 0000000..fc00ab6
Binary files /dev/null and b/testdata/data/too_many_def_levels.parquet differ
diff --git a/tests/query_test/test_scanners.py b/tests/query_test/test_scanners.py
index f2b0c4d..33b433e 100644
--- a/tests/query_test/test_scanners.py
+++ b/tests/query_test/test_scanners.py
@@ -589,6 +589,15 @@ class TestParquet(ImpalaTestSuite):
     self.run_test_case('QueryTest/parquet-num-values-def-levels-mismatch',
         vector, unique_database)
 
+    """IMPALA-11134: Impala returns "Couldn't skip rows in file" error for old
+    (possibly corrupt) Parquet file where there are more def levels than num_values"""
+    create_table_from_parquet(self.client, unique_database,
+        "too_many_def_levels")
+    result = self.client.execute("select i_item_id from {0}."
+        "too_many_def_levels where i_item_sk = 350963".format(unique_database))
+    assert len(result.data) == 1
+    assert "AAAAAAAACPKFFAAA" in result.data
+
   @SkipIfS3.hdfs_block_size
   @SkipIfGCS.hdfs_block_size
   @SkipIfCOS.hdfs_block_size