pvary commented on code in PR #14245:
URL: https://github.com/apache/iceberg/pull/14245#discussion_r2414420129
##########
flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/AvroGenericRecordToRowDataMapper.java:
##########
@@ -41,13 +45,114 @@
public class AvroGenericRecordToRowDataMapper implements
MapFunction<GenericRecord, RowData> {
private final AvroToRowDataConverters.AvroToRowDataConverter converter;
+ private final Schema avroSchema;
+ private final Function<GenericRecord, RowData> customConverter;
- AvroGenericRecordToRowDataMapper(RowType rowType) {
+ AvroGenericRecordToRowDataMapper(RowType rowType, Schema avroSchema) {
+ this.avroSchema = avroSchema;
this.converter = AvroToRowDataConverters.createRowConverter(rowType);
+ // Check if we need custom conversion for timestamp-nanos
+ this.customConverter = needsCustomConversion(avroSchema) ?
this::convertWithNanos : null;
+ }
+
+ private boolean needsCustomConversion(Schema schema) {
+ for (Schema.Field field : schema.getFields()) {
+ if (field.schema().getLogicalType() instanceof
LogicalTypes.TimestampNanos) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private RowData convertWithNanos(GenericRecord genericRecord) {
+ RowData baseRowData = (RowData) converter.convert(genericRecord);
+ GenericRowData result = new GenericRowData(baseRowData.getArity());
Review Comment:
I don't really like this solution. We creating 2 `RowData` objects for a
single conversion.
Can we do this with a single conversion?
--
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]