ahmedabu98 commented on code in PR #32102: URL: https://github.com/apache/beam/pull/32102#discussion_r1716250430
########## sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/RecordWriterManager.java: ########## @@ -0,0 +1,289 @@ +/* + * 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.beam.sdk.io.iceberg; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import org.apache.beam.sdk.transforms.windowing.PaneInfo; +import org.apache.beam.sdk.util.WindowedValue; +import org.apache.beam.sdk.values.Row; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.annotations.VisibleForTesting; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.cache.Cache; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.cache.CacheBuilder; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.cache.RemovalNotification; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Lists; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Maps; +import org.apache.iceberg.DataFile; +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.ManifestFile; +import org.apache.iceberg.ManifestFiles; +import org.apache.iceberg.ManifestWriter; +import org.apache.iceberg.PartitionKey; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Table; +import org.apache.iceberg.catalog.Catalog; +import org.apache.iceberg.data.Record; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.io.OutputFile; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A writer that manages multiple {@link RecordWriter}s to write to multiple tables and partitions. + * Assigns one {@link DestinationState} per windowed destination. A {@link DestinationState} assigns + * one writer per partition in table destination. If the Iceberg {@link Table} is un-partitioned, + * the data is written normally using one {@link RecordWriter} (i.e. the {@link DestinationState} + * has one writer). At any given moment, the number of open data writers should be less than or + * equal to the number of total partitions (across all windowed destinations). + * + * <p>A {@link DestinationState} maintains its writers in a {@link Cache}. If a {@link RecordWriter} + * is inactive for 1 minute, the {@link DestinationState} will automatically close it to free up + * resources. Calling {@link #close()} on this {@link RecordWriterManager} will do the following for + * each {@link DestinationState}: + * + * <ol> + * <li>Close all underlying {@link RecordWriter}s + * <li>Collect all {@link DataFile}s + * <li>Create a new {@link ManifestFile} referencing these {@link DataFile}s + * </ol> + * + * <p>After closing, the resulting {@link ManifestFile}s can be retrieved using {@link + * #getManifestFiles()}. + */ +class RecordWriterManager { Review Comment: I originally had it as `PartitionedRecordWriter` but thought it may be misleading since the class is also used for unpartitioned writes Added Autocloseable implementation -- 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: github-unsubscr...@beam.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org