Fokko commented on code in PR #9502: URL: https://github.com/apache/iceberg/pull/9502#discussion_r1643308001
########## core/src/main/java/org/apache/iceberg/avro/GenericAvroReader.java: ########## @@ -155,6 +162,41 @@ public ValueReader<?> record(Type partner, Schema record, List<ValueReader<?>> f return recordReader(readPlan, avroSchemas.get(partner), record.getFullName()); } + Object toGenericRecord(Type type, Object data) { + // Recursively convert data to GenericRecord if type is a StructType. + // TODO: Rewrite this as a visitor. + if (type instanceof Types.StructType) { + Types.StructType structType = (Types.StructType) type; + GenericData.Record genericRecord = new GenericData.Record(AvroSchemaUtil.convert(type)); + int index = 0; + for (Types.NestedField field : structType.fields()) { + genericRecord.put( + field.name(), toGenericRecord(field.type(), ((GenericRecord) data).get(index))); + index++; Review Comment: Here we assume that the structs are in the same position. For example: ``` struct<a (1): int, b (2): string> ``` But they could be swapped: ``` struct<b (2): string, a (1): int> ``` -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org