pvary commented on code in PR #14040: URL: https://github.com/apache/iceberg/pull/14040#discussion_r2360025639
########## parquet/src/main/java/org/apache/iceberg/data/parquet/InternalReader.java: ########## @@ -20,37 +20,87 @@ import java.util.List; import java.util.Map; +import java.util.function.Function; import org.apache.iceberg.Schema; import org.apache.iceberg.StructLike; +import org.apache.iceberg.data.Record; +import org.apache.iceberg.parquet.Parquet; import org.apache.iceberg.parquet.ParquetValueReader; import org.apache.iceberg.parquet.ParquetValueReaders; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; import org.apache.iceberg.types.Types.StructType; import org.apache.parquet.column.ColumnDescriptor; import org.apache.parquet.schema.MessageType; public class InternalReader<T extends StructLike> extends BaseParquetReaders<T> { + private final Map<Integer, Class<? extends StructLike>> typesById = Maps.newHashMap(); + private static final InternalReader<?> INSTANCE = new InternalReader<>(); private InternalReader() {} @SuppressWarnings("unchecked") public static <T extends StructLike> ParquetValueReader<T> create( - Schema expectedSchema, MessageType fileSchema) { - return (ParquetValueReader<T>) INSTANCE.createReader(expectedSchema, fileSchema); + Schema expectedSchema, MessageType fileSchema, Map<Integer, ?> idToConstant) { + return (ParquetValueReader<T>) INSTANCE.createReader(expectedSchema, fileSchema, idToConstant); } @SuppressWarnings("unchecked") public static <T extends StructLike> ParquetValueReader<T> create( - Schema expectedSchema, MessageType fileSchema, Map<Integer, ?> idToConstant) { - return (ParquetValueReader<T>) INSTANCE.createReader(expectedSchema, fileSchema, idToConstant); + Schema expectedSchema, MessageType fileSchema) { + return (ParquetValueReader<T>) INSTANCE.createReader(expectedSchema, fileSchema); + } + + public static Parquet.ReadBuilder.ReaderFunction readerFunction() { + InternalReader<?> reader = new InternalReader<>(); + + return new Parquet.ReadBuilder.ReaderFunction() { + private Schema schema; + + @Override + public Function<MessageType, ParquetValueReader<?>> apply() { + return messageType -> reader.createReader(schema, messageType); + } + + @Override + public Parquet.ReadBuilder.ReaderFunction withSchema(Schema schema) { + this.schema = schema; + return this; + } + + @Override + public Parquet.ReadBuilder.ReaderFunction withCustomTypes( + Map<Integer, Class<? extends StructLike>> customTypes) { + reader.typesById.putAll(customTypes); + return this; + } + + @Override + public Parquet.ReadBuilder.ReaderFunction withRootType(Class<? extends StructLike> rootType) { + if (rootType != null) { + reader.typesById.put(ROOT_ID, rootType); + } + return this; + } + }; } @Override - @SuppressWarnings("unchecked") protected ParquetValueReader<T> createStructReader( List<ParquetValueReader<?>> fieldReaders, StructType structType) { - return (ParquetValueReader<T>) ParquetValueReaders.recordReader(fieldReaders, structType); + throw new UnsupportedOperationException( Review Comment: Why not remove this function? If not removing, maybe we should deprecate it at least -- 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