Skip to content

Can not read data when there is an required filed under an optional stuct #12441

@zymap

Description

@zymap

Apache Iceberg version

1.8.1 (latest release)

Query engine

None

Please describe the bug 🐞

My table schema is

2025-03-03T17:39:41,451 - INFO  - [main:IcebergTable@131] - Create table with schema table {
  0: address: optional string
  1: age: required int
  2: id: required int
  3: name: optional string
  4: school: optional struct<14: detail: optional string, 15: year: required int>
  5: score: required double
  6: tags: optional map<string, string>
  7: __key: optional binary
  8: __eventTime: optional long
  9: __publishTime: optional long
  10: __properties: optional map<string, string>
  11: __schemaVersion: optional long
  12: __messageOffset: optional long
  13: __partition: optional int
}

When I read data using the IcebergGenerics.read(table).build();, it throws the following exception:

java.lang.IllegalArgumentException: Missing required field: year

	at org.apache.iceberg.data.parquet.BaseParquetReaders$ReadBuilder.struct(BaseParquetReaders.java:326)
	at org.apache.iceberg.data.parquet.BaseParquetReaders$ReadBuilder.struct(BaseParquetReaders.java:252)
	at org.apache.iceberg.parquet.TypeWithSchemaVisitor.visit(TypeWithSchemaVisitor.java:148)
	at org.apache.iceberg.parquet.TypeWithSchemaVisitor.visitField(TypeWithSchemaVisitor.java:183)
	at org.apache.iceberg.parquet.TypeWithSchemaVisitor.visitFields(TypeWithSchemaVisitor.java:198)
	at org.apache.iceberg.parquet.TypeWithSchemaVisitor.visit(TypeWithSchemaVisitor.java:47)
	at org.apache.iceberg.data.parquet.BaseParquetReaders.createReader(BaseParquetReaders.java:69)
	at org.apache.iceberg.data.parquet.GenericParquetReaders.buildReader(GenericParquetReaders.java:56)
	at org.apache.iceberg.data.GenericReader.lambda$openFile$2(GenericReader.java:119)
	at org.apache.iceberg.parquet.ReadConf.<init>(ReadConf.java:121)
	at org.apache.iceberg.parquet.ParquetReader.init(ParquetReader.java:71)
	at org.apache.iceberg.parquet.ParquetReader.iterator(ParquetReader.java:91)
	at org.apache.iceberg.parquet.ParquetReader.iterator(ParquetReader.java:37)
	at org.apache.iceberg.util.Filter.lambda$filter$0(Filter.java:34)
	at org.apache.iceberg.io.CloseableIterable$2.iterator(CloseableIterable.java:89)
	at org.apache.iceberg.io.CloseableIterable$ConcatCloseableIterable$ConcatCloseableIterator.hasNext(CloseableIterable.java:274)

Willingness to contribute

  • I can contribute a fix for this bug independently
  • I would be willing to contribute a fix for this bug with guidance from the Iceberg community
  • I cannot contribute a fix for this bug at this time

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions