rdblue commented on code in PR #12298: URL: https://github.com/apache/iceberg/pull/12298#discussion_r2692508472
########## core/src/main/java/org/apache/iceberg/avro/AvroFormatModel.java: ########## @@ -0,0 +1,260 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg.avro; + +import java.nio.ByteBuffer; +import java.util.Map; +import java.util.function.BiFunction; +import org.apache.avro.io.DatumReader; +import org.apache.avro.io.DatumWriter; +import org.apache.iceberg.FileContent; +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.MetricsConfig; +import org.apache.iceberg.Schema; +import org.apache.iceberg.encryption.EncryptedOutputFile; +import org.apache.iceberg.expressions.Expression; +import org.apache.iceberg.formats.FormatModel; +import org.apache.iceberg.formats.ReadBuilder; +import org.apache.iceberg.formats.WriteBuilder; +import org.apache.iceberg.io.CloseableIterable; +import org.apache.iceberg.io.DeleteSchemaUtil; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; + +public class AvroFormatModel<D, S> implements FormatModel<D, S> { + private final Class<D> type; + private final Class<S> schemaType; + private final BiFunction<Schema, Map<Integer, ?>, DatumReader<D>> readerFunction; + private final BiFunction<org.apache.avro.Schema, S, DatumWriter<D>> writerFunction; Review Comment: I'm going through the different reader/writer functions and how they are supplied by Spark and generics. All of the variations are pretty wacky. This is a good example, where the read side uses an Iceberg `Schema` but the write side uses an Avro schema. In addition, only the write paths for Spark pass the `inputSchema` from Spark (even though the readers are parameterized by its type). I know that we're trying to avoid doing extra work right now, but it seems to me that this is an area where we should do work now since we're ensuring that we can pass the engine schema around and we aren't going to want to make substantial changes to the `FormatModel` interface. What happens if we want to use the Iceberg schema in addition to the Avro schema for writes? I'd like to know now rather than later and would lean toward plumbing it through these interfaces; at a minimum, I'd make sure that we have Iceberg schema, engine schema, and file schema for writes (which is what is needed for Parquet) and I'd pass Iceberg schema, file schema, and constants map for reads. I also suspect that we are going to want engine schema for reads so we may want to add it now as well. Having a common set of metadata supported by the builders and the formats is going to make this easier to think about and build for, without needing to make substantial changes to plumbing when we actually want to use these. -- 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]
