2dmurali opened a new issue, #17943:
URL: https://github.com/apache/iceberg/issues/17943
### Apache Iceberg version
1.11.0 (latest release)
### Query engine
Spark
### Please describe the bug 🐞
### Description
The default Iceberg Parquet Avro writer fails when writing a
`GenericData.Record` containing a logical `Variant` value.
`Parquet.write(...).schema(schema).build()` uses
`ParquetAvro.DEFAULT_MODEL`, which registers `VariantConversion`. However, Avro
looks up conversions using the datum's exact runtime class. Values returned by
`Variant.of(...)` implement `Variant`, but their runtime class is
`VariantData`. Because `VariantConversion#getConvertedType()` returns
`Variant.class`, the conversion is not found.
Avro consequently treats the value as an `IndexedRecord`, resulting in a
`ClassCastException`.
### Reproduction
```java
Schema schema = new Schema(required(1, "v", Types.VariantType.get()));
GenericData.Record record =
new GenericData.Record(AvroSchemaUtil.convert(schema.asStruct(),
"table"));
record.put("v", Variant.of(Variants.emptyMetadata(), Variants.of(34)));
try (FileAppender<GenericData.Record> writer =
Parquet.write(Files.localOutput(file)).schema(schema).build()) {
writer.add(record);
}
```
### Actual behavior
Writing the record fails because `VariantData` cannot be cast to Avro's
`IndexedRecord`.
### Expected behavior
The registered `VariantConversion` should handle any runtime class
implementing `Variant`, allowing the value to be written successfully.
### Willingness to contribute
- [x] I can contribute a fix for this bug independently
- [x] 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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]