rdblue commented on code in PR #12298: URL: https://github.com/apache/iceberg/pull/12298#discussion_r2162619276
########## data/src/main/java/org/apache/iceberg/data/RegistryBasedFileWriterFactory.java: ########## @@ -0,0 +1,196 @@ +/* + * 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.data; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.Map; +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.MetricsConfig; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Schema; +import org.apache.iceberg.SortOrder; +import org.apache.iceberg.StructLike; +import org.apache.iceberg.Table; +import org.apache.iceberg.deletes.EqualityDeleteWriter; +import org.apache.iceberg.deletes.PositionDeleteWriter; +import org.apache.iceberg.encryption.EncryptedOutputFile; +import org.apache.iceberg.encryption.EncryptionKeyMetadata; +import org.apache.iceberg.io.DataWriter; +import org.apache.iceberg.io.FileWriterFactory; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; + +/** + * A base writer factory to be extended by query engine integrations. + * + * @param <T> type of the engine specific records + * @param <S> type of the engine specific schema + */ +public abstract class RegistryBasedFileWriterFactory<T, S> implements FileWriterFactory<T> { + private final Table table; + private final FileFormat dataFileFormat; + private final String inputType; + private final Schema dataSchema; + private final SortOrder dataSortOrder; + private final FileFormat deleteFileFormat; + private final int[] equalityFieldIds; + private final Schema equalityDeleteRowSchema; + private final SortOrder equalityDeleteSortOrder; + private final Schema positionDeleteRowSchema; + private final Map<String, String> writeProperties; + private final S rowSchemaType; + private final S equalityDeleteSchemaType; + private final S positionalDeleteSchemaType; + + protected RegistryBasedFileWriterFactory( + Table table, + FileFormat dataFileFormat, + String inputType, + Schema dataSchema, + SortOrder dataSortOrder, + FileFormat deleteFileFormat, + int[] equalityFieldIds, + Schema equalityDeleteRowSchema, + SortOrder equalityDeleteSortOrder, + Schema positionDeleteRowSchema, + Map<String, String> writeProperties, + S rowSchemaType, + S equalityDeleteSchemaType, + S positionalDeleteSchemaType) { + this.table = table; + this.dataFileFormat = dataFileFormat; + this.inputType = inputType; + this.dataSchema = dataSchema; + this.dataSortOrder = dataSortOrder; + this.deleteFileFormat = deleteFileFormat; + this.equalityFieldIds = equalityFieldIds; + this.equalityDeleteRowSchema = equalityDeleteRowSchema; + this.equalityDeleteSortOrder = equalityDeleteSortOrder; + this.positionDeleteRowSchema = positionDeleteRowSchema; + this.writeProperties = writeProperties != null ? writeProperties : ImmutableMap.of(); + this.rowSchemaType = rowSchemaType; + this.equalityDeleteSchemaType = equalityDeleteSchemaType; + this.positionalDeleteSchemaType = positionalDeleteSchemaType; + } + + protected S rowSchemaType() { Review Comment: I don't think that the term `SchemaType` makes much sense. From the existing usage, I think that `Schema` means the Iceberg schema (as in `positionDeleteRowSchema(Schema)`) and that `Type` is used in this area to mean the object model's schema class (as in `positionDeleteSparkType(StructType)`). Combining them here makes this confusing to me. The ideal solution is to simply remove these and not pass them through the common code. But I think that we do need to pass the object model row type because it may be more specific than the Iceberg type. For instance, Spark may pass a `tinyint` column that needs to be handled by calling `InternalRow#getByte`. If we do need to pass them then I'd like to find a better name. One option is to use "Schema" to describe the Iceberg schema/type and "Type" to describe the object model's schema/type, but that breaks down because Iceberg has a different distinction between schema (top-level table type) and type (primitive or nested type). Since we are talking about "object models" how about using "ModelSchema" for the model-specific type? That's the best I've been able to come up with so far. ########## data/src/main/java/org/apache/iceberg/data/RegistryBasedFileWriterFactory.java: ########## @@ -0,0 +1,196 @@ +/* + * 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.data; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.Map; +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.MetricsConfig; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Schema; +import org.apache.iceberg.SortOrder; +import org.apache.iceberg.StructLike; +import org.apache.iceberg.Table; +import org.apache.iceberg.deletes.EqualityDeleteWriter; +import org.apache.iceberg.deletes.PositionDeleteWriter; +import org.apache.iceberg.encryption.EncryptedOutputFile; +import org.apache.iceberg.encryption.EncryptionKeyMetadata; +import org.apache.iceberg.io.DataWriter; +import org.apache.iceberg.io.FileWriterFactory; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; + +/** + * A base writer factory to be extended by query engine integrations. + * + * @param <T> type of the engine specific records + * @param <S> type of the engine specific schema + */ +public abstract class RegistryBasedFileWriterFactory<T, S> implements FileWriterFactory<T> { + private final Table table; + private final FileFormat dataFileFormat; + private final String inputType; + private final Schema dataSchema; + private final SortOrder dataSortOrder; + private final FileFormat deleteFileFormat; + private final int[] equalityFieldIds; + private final Schema equalityDeleteRowSchema; + private final SortOrder equalityDeleteSortOrder; + private final Schema positionDeleteRowSchema; + private final Map<String, String> writeProperties; + private final S rowSchemaType; + private final S equalityDeleteSchemaType; + private final S positionalDeleteSchemaType; + + protected RegistryBasedFileWriterFactory( + Table table, + FileFormat dataFileFormat, + String inputType, + Schema dataSchema, + SortOrder dataSortOrder, + FileFormat deleteFileFormat, + int[] equalityFieldIds, + Schema equalityDeleteRowSchema, + SortOrder equalityDeleteSortOrder, + Schema positionDeleteRowSchema, + Map<String, String> writeProperties, + S rowSchemaType, + S equalityDeleteSchemaType, + S positionalDeleteSchemaType) { + this.table = table; + this.dataFileFormat = dataFileFormat; + this.inputType = inputType; + this.dataSchema = dataSchema; + this.dataSortOrder = dataSortOrder; + this.deleteFileFormat = deleteFileFormat; + this.equalityFieldIds = equalityFieldIds; + this.equalityDeleteRowSchema = equalityDeleteRowSchema; + this.equalityDeleteSortOrder = equalityDeleteSortOrder; + this.positionDeleteRowSchema = positionDeleteRowSchema; + this.writeProperties = writeProperties != null ? writeProperties : ImmutableMap.of(); + this.rowSchemaType = rowSchemaType; + this.equalityDeleteSchemaType = equalityDeleteSchemaType; + this.positionalDeleteSchemaType = positionalDeleteSchemaType; + } + + protected S rowSchemaType() { Review Comment: I don't think that the term `SchemaType` makes much sense. From the existing usage, I think that `Schema` means the Iceberg schema (as in `positionDeleteRowSchema(Schema)`) and that `Type` is used in this area to mean the object model's schema class (as in `positionDeleteSparkType(StructType)`). Combining them here makes this confusing to me. The ideal solution is to simply remove these and not pass them through the common code. But I think that we do need to pass the object model row type because it may be more specific than the Iceberg type. For instance, Spark may pass a `tinyint` column that needs to be handled by calling `InternalRow#getByte`. If we do need to pass them then I'd like to find a better name. One option is to use "Schema" to describe the Iceberg schema/type and "Type" to describe the object model's schema/type, but that breaks down because Iceberg has a different distinction between schema (top-level table type) and type (primitive or nested type). Since we are talking about "object models" how about using "ModelSchema" or "ModelType" for the model-specific type? That's the best I've been able to come up with so far. -- 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