ahmedabu98 commented on code in PR #39997: URL: https://github.com/apache/beam/pull/39997#discussion_r3929370532
########## sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/cdc/sink/CdcWriteConfig.java: ########## @@ -0,0 +1,231 @@ +/* + * 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.cdc.sink; + +import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkArgument; + +import com.google.auto.value.AutoValue; +import java.io.Serializable; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import org.apache.beam.sdk.io.iceberg.cdc.IcebergCdcMetadataColumns; +import org.apache.beam.sdk.values.ValueKind; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** Configuration for the CDC sink. */ +@AutoValue +abstract class CdcWriteConfig implements Serializable { + static final String DEFAULT_SEQUENCE_NUMBER_COLUMN = + IcebergCdcMetadataColumns.COMMIT_SNAPSHOT_SEQUENCE_NUMBER; + + /** + * Every shard that touches a partition writes a file per commit window, so {@code num_shards x + * touched partitions x windows per day} files. On a <b>partitioned</b> table {@link + * #getShardsPerPartition()} caps the per-partition factor without lowering this number, trading + * per-partition write parallelism for proportionally fewer files. + */ + static final int DEFAULT_NUM_SHARDS = 16; + + static final int DEFAULT_SORTER_MEMORY_MB = 100; + + /** + * Columns that define a row's identity (the Iceberg equality-delete fields). If unspecified, will + * try to use the destination table's identifier fields. + */ + abstract @Nullable List<String> getEqualityColumns(); + + /** + * The column holding the per-primary-key monotonic sequence number used to order a single key's + * changes. Defaults to {@value #DEFAULT_SEQUENCE_NUMBER_COLUMN}. + */ + abstract String getSequenceNumberColumn(); + + /** + * If set, the change kind is read from this string column instead of the element's native {@link + * ValueKind}. The column is stripped from the data row and never written to Iceberg. + */ + abstract @Nullable String getChangeTypeColumn(); + + /** + * Optional mapping from {@link #getChangeTypeColumn()} values to {@link ValueKind} names (e.g. + * {@code {"c": "INSERT", "u": "UPDATE_AFTER", "d": "DELETE"}}). If {@code null}, {@link + * #getChangeTypeColumn()} values must already be {@link ValueKind} names. + */ + abstract @Nullable Map<String, String> getChangeTypeMap(); + + /** + * The number of deterministic primary-key-hash shards (logical write buckets) per destination. + * Defaults to {@value #DEFAULT_NUM_SHARDS}; set it to about your pipeline's write parallelism. + */ + abstract int getNumShards(); + + /** + * The maximum number of shards a single partition's rows may occupy on a <b>partitioned</b> + * destination. A {@code (destination, window)} writes about {@code min(shards_per_partition, + * distinct keys)} files per touched partition, and per-partition write parallelism is capped at + * this value. {@code 1} pins each partition to a single writer, {@code num_shards} is plain + * primary-key sharding. Ignored for an unpartitioned destination, which always shards by primary + * key. + */ + abstract int getShardsPerPartition(); + Review Comment: We're doing this in the main WriteCdcRows transform (full change: #39978) -- 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]
