Read ORC table with nested partition column can lead to ArrayIndexOutOfBoundsException
This can be reproduced by modifying test TestPartitionValues::testPartitionedByNestedString, to let it write with ORC format instead of parquet, e.g. with the following change:
// write into iceberg
sourceDF.write()
.format("iceberg")
.option(WRITE_FORMAT, format) // add this line
.mode(SaveMode.Append)
.save(baseLocation);
And the test would fail with:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:659)
at java.util.ArrayList.get(ArrayList.java:435)
at org.apache.iceberg.orc.OrcValueReaders$StructReader.<init>(OrcValueReaders.java:161)
at org.apache.iceberg.spark.data.SparkOrcValueReaders$StructReader.<init>(SparkOrcValueReaders.java:143)
at org.apache.iceberg.spark.data.SparkOrcValueReaders.struct(SparkOrcValueReaders.java:70)
at org.apache.iceberg.spark.data.SparkOrcReader$ReadBuilder.record(SparkOrcReader.java:75)
at org.apache.iceberg.spark.data.SparkOrcReader$ReadBuilder.record(SparkOrcReader.java:65)
at org.apache.iceberg.orc.OrcSchemaWithTypeVisitor.visitRecord(OrcSchemaWithTypeVisitor.java:71)
at org.apache.iceberg.orc.OrcSchemaWithTypeVisitor.visit(OrcSchemaWithTypeVisitor.java:38)
at org.apache.iceberg.orc.OrcSchemaWithTypeVisitor.visit(OrcSchemaWithTypeVisitor.java:32)
at org.apache.iceberg.spark.data.SparkOrcReader.<init>(SparkOrcReader.java:52)
at org.apache.iceberg.spark.source.RowDataReader.lambda$newOrcIterable$2(RowDataReader.java:164)
at org.apache.iceberg.orc.OrcIterable.iterator(OrcIterable.java:108)
at org.apache.iceberg.orc.OrcIterable.iterator(OrcIterable.java:45)
at org.apache.iceberg.util.Filter.lambda$filter$0(Filter.java:35)
at org.apache.iceberg.io.CloseableIterable$2.iterator(CloseableIterable.java:73)
at org.apache.iceberg.spark.source.RowDataReader.open(RowDataReader.java:78)
In RowDataReader::newOrcIterable, we exclude the struct field and create an OrcIterable with an empty schema, because the inner string is a constant (partition value). And later on we hit the exception when constructing the readers.
Interesting , thanks for the report @lirui-apache , would you like to propose a PR for this bug ?
Hey @openinx , I haven't decided what's the right way to fix this. A possible solution is to improve how we generate idToConstant in RowDataReader::open. Currently we only put metadata column and partition value into that map. Perhaps we can also do a DFS walk of the required schema, and if all nested fields of a compound type are constants, then the compound column itself can be considered a constant too. Does that make sense to you?
@lirui-apache Could you please let me take this issue ? I would like to try this.
@zhangminglei Sure, feel free to propose a PR.
https://github.com/apache/iceberg/pull/3186
@openinx Hi, I've gave a PR to fix this. Could you please take a review ?
This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.
This issue has been closed because it has not received any activity in the last 14 days since being marked as 'stale'