diff --git a/parquet/src/main/java/org/apache/iceberg/data/parquet/InternalReader.java b/parquet/src/main/java/org/apache/iceberg/data/parquet/InternalReader.java index be62a3bcb0f0..043d2be9ad35 100644 --- a/parquet/src/main/java/org/apache/iceberg/data/parquet/InternalReader.java +++ b/parquet/src/main/java/org/apache/iceberg/data/parquet/InternalReader.java @@ -21,7 +21,7 @@ import java.util.List; import java.util.Map; import org.apache.iceberg.Schema; -import org.apache.iceberg.data.Record; +import org.apache.iceberg.StructLike; import org.apache.iceberg.parquet.ParquetValueReader; import org.apache.iceberg.parquet.ParquetValueReaders; import org.apache.iceberg.types.Types.StructType; @@ -31,25 +31,28 @@ import org.apache.parquet.schema.PrimitiveType; import org.apache.parquet.schema.Type; -public class InternalReader extends BaseParquetReaders { +public class InternalReader extends BaseParquetReaders { - private static final InternalReader INSTANCE = new InternalReader(); + private static final InternalReader INSTANCE = new InternalReader<>(); private InternalReader() {} - public static ParquetValueReader create(Schema expectedSchema, MessageType fileSchema) { - return INSTANCE.createReader(expectedSchema, fileSchema); + @SuppressWarnings("unchecked") + public static ParquetValueReader create(Schema expectedSchema, MessageType fileSchema) { + return (ParquetValueReader) INSTANCE.createReader(expectedSchema, fileSchema); } - public static ParquetValueReader create( + @SuppressWarnings("unchecked") + public static ParquetValueReader create( Schema expectedSchema, MessageType fileSchema, Map idToConstant) { - return INSTANCE.createReader(expectedSchema, fileSchema, idToConstant); + return (ParquetValueReader) INSTANCE.createReader(expectedSchema, fileSchema, idToConstant); } @Override - protected ParquetValueReader createStructReader( + @SuppressWarnings("unchecked") + protected ParquetValueReader createStructReader( List types, List> fieldReaders, StructType structType) { - return ParquetValueReaders.recordReader(types, fieldReaders, structType); + return (ParquetValueReader) ParquetValueReaders.recordReader(types, fieldReaders, structType); } @Override @@ -66,7 +69,7 @@ protected ParquetValueReader dateReader(ColumnDescriptor desc) { protected ParquetValueReader timeReader( ColumnDescriptor desc, LogicalTypeAnnotation.TimeUnit unit) { if (unit == LogicalTypeAnnotation.TimeUnit.MILLIS) { - return ParquetValueReaders.millisAsTimestamps(desc); + return ParquetValueReaders.millisAsTimes(desc); } return new ParquetValueReaders.UnboxedReader<>(desc); diff --git a/parquet/src/main/java/org/apache/iceberg/data/parquet/InternalWriter.java b/parquet/src/main/java/org/apache/iceberg/data/parquet/InternalWriter.java index 128cc46b3542..b42f07ce18ce 100644 --- a/parquet/src/main/java/org/apache/iceberg/data/parquet/InternalWriter.java +++ b/parquet/src/main/java/org/apache/iceberg/data/parquet/InternalWriter.java @@ -33,17 +33,18 @@ *

Iceberg's internal in-memory object model produces the types defined in {@link * Type.TypeID#javaClass()}. */ -public class InternalWriter extends BaseParquetWriter { - private static final InternalWriter INSTANCE = new InternalWriter(); +public class InternalWriter extends BaseParquetWriter { + private static final InternalWriter INSTANCE = new InternalWriter<>(); private InternalWriter() {} - public static ParquetValueWriter create(MessageType type) { - return INSTANCE.createWriter(type); + @SuppressWarnings("unchecked") + public static ParquetValueWriter create(MessageType type) { + return (ParquetValueWriter) INSTANCE.createWriter(type); } @Override - protected StructWriter createStructWriter(List> writers) { + protected StructWriter createStructWriter(List> writers) { return ParquetValueWriters.recordWriter(writers); } diff --git a/parquet/src/main/java/org/apache/iceberg/parquet/ParquetValueReaders.java b/parquet/src/main/java/org/apache/iceberg/parquet/ParquetValueReaders.java index 0b67359e576f..31f73b3bce74 100644 --- a/parquet/src/main/java/org/apache/iceberg/parquet/ParquetValueReaders.java +++ b/parquet/src/main/java/org/apache/iceberg/parquet/ParquetValueReaders.java @@ -77,6 +77,10 @@ public static ParquetValueReader int96Timestamps(ColumnDescriptor desc) { return new ParquetValueReaders.TimestampInt96Reader(desc); } + public static ParquetValueReader millisAsTimes(ColumnDescriptor desc) { + return new ParquetValueReaders.TimeMillisReader(desc); + } + public static ParquetValueReader millisAsTimestamps(ColumnDescriptor desc) { return new ParquetValueReaders.TimestampMillisReader(desc); } @@ -465,6 +469,22 @@ public long readLong() { } } + private static class TimeMillisReader extends UnboxedReader { + private TimeMillisReader(ColumnDescriptor desc) { + super(desc); + } + + @Override + public Long read(Long ignored) { + return readLong(); + } + + @Override + public long readLong() { + return 1000L * column.nextInteger(); + } + } + private static class TimestampMillisReader extends UnboxedReader { private TimestampMillisReader(ColumnDescriptor desc) { super(desc); @@ -477,7 +497,7 @@ public Long read(Long ignored) { @Override public long readLong() { - return 1000L * column.nextInteger(); + return 1000L * column.nextLong(); } }