rdblue commented on code in PR #11904: URL: https://github.com/apache/iceberg/pull/11904#discussion_r1925927030
########## parquet/src/main/java/org/apache/iceberg/data/parquet/GenericParquetReaders.java: ########## @@ -49,47 +59,132 @@ public static ParquetValueReader<Record> buildReader( @Override protected ParquetValueReader<Record> createStructReader( List<Type> types, List<ParquetValueReader<?>> fieldReaders, StructType structType) { - return new RecordReader(types, fieldReaders, structType); + return ParquetValueReaders.recordReader(types, fieldReaders, structType); } @Override protected Object convertConstant(org.apache.iceberg.types.Type type, Object value) { return GenericDataUtil.internalToGeneric(type, value); } - private static class RecordReader extends StructReader<Record, Record> { - private final GenericRecord template; + private static final OffsetDateTime EPOCH = Instant.ofEpochSecond(0).atOffset(ZoneOffset.UTC); + private static final LocalDate EPOCH_DAY = EPOCH.toLocalDate(); - RecordReader(List<Type> types, List<ParquetValueReader<?>> readers, StructType struct) { - super(types, readers); - this.template = struct != null ? GenericRecord.create(struct) : null; + protected static class DateReader extends ParquetValueReaders.PrimitiveReader<LocalDate> { + protected DateReader(ColumnDescriptor desc) { + super(desc); } @Override - protected Record newStructData(Record reuse) { - if (reuse != null) { - return reuse; - } else { - // GenericRecord.copy() is more performant then GenericRecord.create(StructType) since - // NAME_MAP_CACHE access - // is eliminated. Using copy here to gain performance. - return template.copy(); - } + public LocalDate read(LocalDate reuse) { + return EPOCH_DAY.plusDays(column.nextInteger()); + } + } + + protected static class TimestampReader + extends ParquetValueReaders.PrimitiveReader<LocalDateTime> { + protected TimestampReader(ColumnDescriptor desc) { + super(desc); } @Override - protected Object getField(Record intermediate, int pos) { - return intermediate.get(pos); + public LocalDateTime read(LocalDateTime reuse) { + return EPOCH.plus(column.nextLong(), ChronoUnit.MICROS).toLocalDateTime(); + } + } + + protected static class TimestampMillisReader + extends ParquetValueReaders.PrimitiveReader<LocalDateTime> { + protected TimestampMillisReader(ColumnDescriptor desc) { + super(desc); } @Override - protected Record buildStruct(Record struct) { - return struct; + public LocalDateTime read(LocalDateTime reuse) { + return EPOCH.plus(column.nextLong() * 1000, ChronoUnit.MICROS).toLocalDateTime(); + } + } + + protected static class TimestampInt96Reader Review Comment: I think this and the other classes should be package-private rather than protected. -- 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