ganesh-skumar commented on code in PR #41615:
URL: https://github.com/apache/beam/pull/41615#discussion_r4757634146


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/BatchElements.java:
##########
@@ -88,23 +88,116 @@
  *             }));
  * }</pre>
  *
+ * <h3>Batching Modes</h3>
+ *
+ * <p>Depending on whether {@link #withElementSizeFn(SerializableFunction)} 
and {@link
+ * #withMaxBatchWeight(long)} are configured, {@link BatchElements} operates 
in one of three modes:
+ *
+ * <pre>{@code
+ * // Mode 1: Count-based (default)
+ * // Every element has size 1; the adaptive target batch size is measured in 
element count.
+ * BatchElements.<String>withDefaults();
+ *
+ * // Mode 2: Custom sizing
+ * // Each element contributes elementSizeFn(element); the adaptive target 
batch size
+ * // (between minBatchSize and maxBatchSize) is measured in custom element 
size units.
+ * BatchElements.<String>withDefaults()
+ *     .withElementSizeFn(String::length);
+ *
+ * // Mode 3: Count + weight constraints
+ * // Adaptive element COUNT (between minBatchSize and maxBatchSize) + hard 
maximum TOTAL WEIGHT
+ * // (sum of elementSizeFn(element) <= maxBatchWeight).
+ * BatchElements.<String>withDefaults()
+ *     .withElementSizeFn(String::length)
+ *     .withMaxBatchWeight(1024);
+ * }</pre>
+ *
  * @param <T> the type of input elements
  */
 public class BatchElements<T> extends PTransform<PCollection<T>, 
PCollection<List<T>>> {
 
   private final BatchConfig config;
-
-  private BatchElements(BatchConfig config) {
+  private final @Nullable SerializableFunction<T, Integer> elementSizeFn;
+  private final @Nullable Long maxBatchWeight;
+
+  private BatchElements(
+      BatchConfig config,
+      @Nullable SerializableFunction<T, Integer> elementSizeFn,
+      @Nullable Long maxBatchWeight) {
+    if (config == null) {
+      throw new IllegalArgumentException("config must not be null");
+    }

Review Comment:
   fixed



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