iceberg icon indicating copy to clipboard operation
iceberg copied to clipboard

Read ORC table with nested partition column can lead to ArrayIndexOutOfBoundsException

Open lirui-apache opened this issue 5 years ago • 7 comments

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.

lirui-apache avatar Sep 17 '21 11:09 lirui-apache

Interesting , thanks for the report @lirui-apache , would you like to propose a PR for this bug ?

openinx avatar Sep 22 '21 02:09 openinx

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 avatar Sep 23 '21 03:09 lirui-apache

@lirui-apache Could you please let me take this issue ? I would like to try this.

rice668 avatar Sep 23 '21 04:09 rice668

@zhangminglei Sure, feel free to propose a PR.

lirui-apache avatar Sep 24 '21 02:09 lirui-apache

https://github.com/apache/iceberg/pull/3186

@openinx Hi, I've gave a PR to fix this. Could you please take a review ?

rice668 avatar Sep 27 '21 13:09 rice668

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.

github-actions[bot] avatar Jul 25 '24 00:07 github-actions[bot]

This issue has been closed because it has not received any activity in the last 14 days since being marked as 'stale'

github-actions[bot] avatar Aug 21 '24 00:08 github-actions[bot]