[parquet-java] Intermittent out-of-bounds dictionary ID when reading dictionary-encoded Parquet pages
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 1.6k
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 33
Description
### Describe the bug, including details regarding any error messages, version, and platform.
## Description
We intermittently encounter a `ParquetDecodingException` when reading Parquet files written by Apache Hudi with Spark.
The issue cannot be reproduced consistently for every write, but it has occurred repeatedly across different write jobs.
The failures have a similar call chain: while reading a dictionary-encoded data page, parquet-java decodes a dictionary ID that is outside the range of the current dictionary. `PlainValuesDictionary` then attempts to access the dictionary array with that ID and throws an `ArrayIndexOutOfBoundsException`.
In the representative case below, the affected column is:
```text
optional int32 chan_second_cate_cd
```
The dictionary contains 13 entries, so the valid dictionary IDs are `0` through `12`. However, the data page produces dictionary ID `14`, resulting in:
```text
java.lang.ArrayIndexOutOfBoundsException: Index 14 out of bounds for length 13
```
This failure occurs in row group `0`, at column value `292293` out of `478848`, and at value `12293` out of `20000` in the current data page.
The value `14` is an internal Parquet dictionary ID, not the actual value stored in the column.
## Environment
| Component | Version |
| --- | --- |
| Apache Hudi | `0.13.1` |
| Write engine | Apache Spark `3.4` |
| parquet-mr | `1.12.3` |
## Representative Stack Trace
Click to expand
```text
org.apache.parquet.io.ParquetDecodingException: Can not read value at 292293 in block 0 in file
at org.apache.parquet.hadoop.InternalParquetRecordReader.nextKeyValue(InternalParquetRecordReader.java:264)
at org.apache.parquet.hadoop.ParquetRecordReader.nextKeyValue(ParquetRecordReader.java:207)
at org.apache.spark.sql.execution.datasources.RecordReaderIterator.hasNext(RecordReaderIterator.scala:39)
at org.apache.spark.sql.execution.datasources.RecordReaderIterator$$anon$1.hasNext(RecordReaderIterator.scala:61)
at org.apache.spark.sql.execution.datasources.FileScanRDD$$anon$1.hasNext(FileScanRDD.scala:125)
at scala.collection.Iterator$$anon$10.hasNext(Iterator.scala:460)
at org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIteratorForCodegenStage1.processNext(Unknown Source)
at org.apache.spark.sql.execution.BufferedRowIterator.hasNext(BufferedRowIterator.java:43)
at org.apache.spark.sql.execution.WholeStageCodegenExec$$anon$1.hasNext(WholeStageCodegenExec.scala:760)
at org.apache.spark.shuffle.sort.BypassMergeSortShuffleWriter.write(BypassMergeSortShuffleWriter.java:140)
at org.apache.spark.shuffle.ShuffleWriteProcessor.write(ShuffleWriteProcessor.scala:59)
at org.apache.spark.scheduler.ShuffleMapTask.runTask(ShuffleMapTask.scala:101)
at org.apache.spark.scheduler.Task.run(Task.scala:140)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:565)
Caused by: org.apache.parquet.io.ParquetDecodingException: Can't read value in column [chan_second_cate_cd] optional int32 chan_second_cate_cd at value 292293 out of 478848, 12293 out of 20000 in currentPage. repetition level: 0, definition level: 1
at org.apache.parquet.column.impl.ColumnReaderBase.readValue(ColumnReaderBase.java:553)
at org.apache.parquet.column.impl.ColumnReaderImpl.readValue(ColumnReaderImpl.java:30)
at org.apache.parquet.column.impl.ColumnReaderBase.writeCurrentValueToConverter(ColumnReaderBase.java:439)
at org.apache.parquet.column.impl.ColumnReaderImpl.writeCurrentValueToConverter(ColumnReaderImpl.java:30)
at org.apache.parquet.io.RecordReaderImplementation.read(RecordReaderImplementation.java:406)
at org.apache.parquet.hadoop.InternalParquetRecordReader.nextKeyValue(InternalParquetRecordReader.java:234)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 14 out of bounds for length 13
at org.apache.parquet.column.values.dictionary.PlainValuesDictionary$PlainIntegerDictionary.decodeToInt(PlainValuesDictionary.java:251)
at org.apache.parquet.column.values.dictionary.DictionaryValuesReader.readInteger(DictionaryValuesReader.java:108)
at org.apache.parquet.column.impl.ColumnReaderBase$2$3.read(ColumnReaderBase.java:279)
at org.apache.parquet.column.impl.ColumnReaderBase.readValue(ColumnReaderBase.java:533)
```
### Component(s)
_No response_
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with PlainValuesDictionary.decodeToInt, DictionaryValuesReader.readInteger, and the ColumnReaderBase call chain shown in the stack trace. Investigate how dictionary IDs are produced while reading dictionary-encoded pages, using the reported 13-entry dictionary and ID 14 as the reference case. Done means the affected pages can be read without an out-of-bounds dictionary access and the intermittent failure is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- data-engineering
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 42/100