pvary commented on code in PR #12298: URL: https://github.com/apache/iceberg/pull/12298#discussion_r2001637794
########## core/src/main/java/org/apache/iceberg/io/datafile/WriteBuilder.java: ########## @@ -0,0 +1,340 @@ +/* + * 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.io.datafile; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import org.apache.iceberg.DeleteFile; +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.EncryptionKeyMetadata; +import org.apache.iceberg.io.DataWriter; +import org.apache.iceberg.io.DeleteSchemaUtil; +import org.apache.iceberg.io.FileAppender; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.util.ArrayUtil; + +/** + * Builder for generating one of the following: + * + * <ul> + * <li>{@link FileAppender} + * <li>{@link DataWriter} + * <li>{@link EqualityDeleteWriter} + * <li>{@link PositionDeleteWriter} + * </ul> + * + * The builder wraps the file format specific {@link AppenderBuilder}. To allow further engine and + * file format specific configuration changes for the given writer the {@link + * AppenderBuilder#build(AppenderBuilder.WriteMode)} method is called with the correct parameter to + * create the appender used internally by the file appender and the writers. + * + * @param <A> type of the appender + * @param <E> engine specific schema of the input records used for appender initialization + */ +public class WriteBuilder<A extends AppenderBuilder<A, E>, E> { + private final AppenderBuilder<A, E> appenderBuilder; + private final String location; + private final FileFormat format; + private PartitionSpec spec = null; + private StructLike partition = null; + private EncryptionKeyMetadata keyMetadata = null; + private SortOrder sortOrder = null; + private Schema rowSchema = null; + private int[] equalityFieldIds = null; + + WriteBuilder(AppenderBuilder<A, E> appenderBuilder, String location, FileFormat format) { + this.appenderBuilder = appenderBuilder; + this.location = location; + this.format = format; + } + + /** + * Sets the configurations coming from the table like {@link #schema(Schema)}, {@link #set(Map)} + * and {@link #metricsConfig(MetricsConfig)}. + */ + public WriteBuilder<A, E> forTable(Table table) { + appenderBuilder.forTable(table); + return this; + } + + /** Set the file schema. */ + public WriteBuilder<A, E> schema(Schema newSchema) { + appenderBuilder.schema(newSchema); + return this; + } + + /** + * Sets the engine specific schema for the input. Used by the {@link + * AppenderBuilder#build(AppenderBuilder.WriteMode)} to configure the engine specific converters. + */ + public WriteBuilder<A, E> engineSchema(E engineSchema) { + appenderBuilder.engineSchema(engineSchema); + return this; + } + + /** Set the file schema's root name. */ + public WriteBuilder<A, E> named(String newName) { + appenderBuilder.named(newName); + return this; + } + + /** + * Set a writer configuration property. + * + * <p>Write configuration affects writer behavior. To add file metadata properties, use {@link + * #meta(String, String)} or {@link #meta(Map)}. + * + * @param property a writer config property name + * @param value config value + * @return this for method chaining + */ + public WriteBuilder<A, E> set(String property, String value) { + appenderBuilder.set(property, value); + return this; + } + + /** + * Adds the new properties to the writer configuration. + * + * <p>Write configuration affects writer behavior. To add file metadata properties, use {@link + * #meta(String, String)} or {@link #meta(Map)}. + * + * @param properties a map of writer config properties + * @return this for method chaining + */ + public WriteBuilder<A, E> set(Map<String, String> properties) { Review Comment: This was a hard decision. We have meta(String, String), and meta(Map), set(String,String) in the InternalData. We have set(String, String) and setAll(Map) in the current writers. I opted for consistency in the new API, and went for set. Since it is a new API, I think better to be consistent -- 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