You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/07/21 21:34:57 UTC

[GitHub] [beam] jhnmora000 commented on a change in pull request #12313: Implement navigation functions

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



##########
File path: sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/transform/BeamBuiltinAnalyticFunctions.java
##########
@@ -42,4 +44,77 @@
     throw new UnsupportedOperationException(
         String.format("Analytics Function [%s] is not supported", functionName));
   }
+
+  public static <T> Combine.CombineFn<T, ?, T> navigationFirstValue() {
+    return new FirstValueCombineFn();
+  }
+
+  public static <T> Combine.CombineFn<T, ?, T> navigationLastValue() {
+    return new LastValueCombineFn();
+  }
+
+  private static class FirstValueCombineFn<T> extends Combine.CombineFn<T, Optional<T>, T> {
+    private FirstValueCombineFn() {}
+
+    @Override
+    public Optional<T> createAccumulator() {
+      return Optional.empty();
+    }
+
+    @Override
+    public Optional<T> addInput(Optional<T> accumulator, T input) {
+      Optional<T> r = accumulator;
+      if (!accumulator.isPresent()) {
+        r = Optional.of(input);
+      }
+      return r;
+    }
+
+    @Override
+    public Optional<T> mergeAccumulators(Iterable<Optional<T>> accumulators) {
+      Optional<T> r = Optional.empty();
+      for (Optional<T> ac : accumulators) {
+        if (!r.isPresent() && ac.isPresent()) {
+          r = ac;

Review comment:
       Since, navigation functions rely on a sorted input and the addInput method actually should be called synchronously, the mergeAccumulators method never is invoked. So, I was wondering If I would rather remove this code and leave a mock implementation (let's say return null). What do you think? 




----------------------------------------------------------------
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:
users@infra.apache.org