jhnmora000 commented on a change in pull request #11333:
URL: https://github.com/apache/beam/pull/11333#discussion_r418279156



##########
File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Sample.java
##########
@@ -246,6 +254,36 @@ private SampleAnyCombineFn(long limit) {
     }
   }
 
+  /** A {@link CombineFn} that combines into a single element. */
+  private static class AnyValueCombineFn<T> extends CombineFn<T, List<T>, T> {
+    private SampleAnyCombineFn internal;
+
+    private AnyValueCombineFn() {
+      internal = new SampleAnyCombineFn<>(1);
+    }
+
+    @Override
+    public List<T> createAccumulator() {
+      return internal.createAccumulator();
+    }
+
+    @Override
+    public List<T> addInput(List<T> accumulator, T input) {
+      return internal.addInput(accumulator, input);
+    }
+
+    @Override
+    public List<T> mergeAccumulators(Iterable<List<T>> accumulators) {
+      return internal.mergeAccumulators(accumulators);
+    }
+
+    @Override
+    public T extractOutput(List<T> accumulator) {
+      Iterator<T> it = internal.extractOutput(accumulator).iterator();
+      return it.hasNext() ? it.next() : null;

Review comment:
       Yes, I was aware of that. I thought that I could have used java 
Optional<T> or similar, but I was not sure it would be compliant with other 
components. Are there other functions that return optional or nullable objects 
in the Java SDK?, I could give them a look.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to