nitinware commented on code in PR #41753:
URL: https://github.com/apache/beam/pull/41753#discussion_r4748914760


##########
sdks/java/io/clickhouse/src/main/java/org/apache/beam/sdk/io/clickhouse/ClickHouseRangePartitioner.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 static 
org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkArgument;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/** Generates non-overlapping ranges covering an inclusive numeric interval. */
+final class ClickHouseRangePartitioner {
+  private ClickHouseRangePartitioner() {}
+
+  static long inclusiveCardinality(long lower, long upper) {
+    checkArgument(lower <= upper, "Lower bound must be less than or equal to 
upper bound");
+    try {
+      return Math.addExact(Math.subtractExact(upper, lower), 1L);
+    } catch (ArithmeticException e) {
+      throw new IllegalArgumentException(
+          "Inclusive range cardinality must fit in a signed long; this is a v1 
implementation restriction");
+    }
+  }
+
+  static final int MAX_PARTITIONS = 10_000;
+
+  static int effectivePartitionCount(long cardinality, int 
requestedPartitions) {
+    checkArgument(requestedPartitions >= 1, "Partition count must be at least 
1");
+    int count = (int) Math.min(requestedPartitions, cardinality);
+    checkArgument(
+        count <= MAX_PARTITIONS,
+        "Effective partition count must not exceed %s; partitions are 
materialized in the pipeline graph",
+        MAX_PARTITIONS);
+    return count;
+  }

Review Comment:
   Removed the 10,000-partition cap. Ranges are now generated lazily at 
runtime, without allocating a list of all descriptors or embedding them in the 
pipeline graph.



-- 
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]

Reply via email to