nitinware commented on code in PR #41753: URL: https://github.com/apache/beam/pull/41753#discussion_r4748676393
########## sdks/java/io/clickhouse/src/main/java/org/apache/beam/sdk/io/clickhouse/ClickHouseReadPartitions.java: ########## @@ -0,0 +1,60 @@ +/* + * 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.clickhouse; + +import java.util.List; +import java.util.stream.Collectors; +import org.apache.beam.sdk.transforms.Create; +import org.apache.beam.sdk.transforms.PTransform; +import org.apache.beam.sdk.transforms.Reshuffle; +import org.apache.beam.sdk.values.PBegin; +import org.apache.beam.sdk.values.PCollection; + +/** Creates explicitly coded work items and a shuffle boundary for partitioned reads. */ +final class ClickHouseReadPartitions + extends PTransform<PBegin, PCollection<ClickHouseReadPartition>> { + private final ClickHouseIO.Read configuration; + + ClickHouseReadPartitions(ClickHouseIO.Read configuration) { + this.configuration = configuration; + } + + @Override + public PCollection<ClickHouseReadPartition> expand(PBegin input) { + if (configuration.query() != null) { + return input.apply( + "QueryWorkItem", + Create.of(ClickHouseReadPartition.singleQuery()) + .withCoder(ClickHouseReadPartitionCoder.of())); + } + Long lower = configuration.lowerBound(); + Long upper = configuration.upperBound(); + Integer count = configuration.numPartitions(); + if (lower == null || upper == null || count == null) { + throw new IllegalArgumentException("Missing partition bounds or count"); + } + List<ClickHouseReadPartition> partitions = + ClickHouseRangePartitioner.partition(lower, upper, count).stream() + .map(ClickHouseReadPartition::forRange) + .collect(Collectors.toList()); + // Create materializes work items in the graph. Scheduling/concurrency remain runner-dependent. + return input + .apply("RangeWorkItems", Create.of(partitions).withCoder(ClickHouseReadPartitionCoder.of())) + .apply("DistributeRanges", Reshuffle.viaRandomKey()); Review Comment: Replaced the duplicate validation branch with checkStateNotNull(). Missing-schema validation remains in the transform’s configuration validation. -- 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]
