[ 
https://issues.apache.org/jira/browse/BEAM-10551?focusedWorklogId=461771&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-461771
 ]

ASF GitHub Bot logged work on BEAM-10551:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 21/Jul/20 22:53
            Start Date: 21/Jul/20 22:53
    Worklog Time Spent: 10m 
      Work Description: amaliujia commented on a change in pull request #12313:
URL: https://github.com/apache/beam/pull/12313#discussion_r458434671



##########
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:
       Ah I see. Yes it's actually called sequentially on the sorted input.
   
   I think you can through an 
[UnsupportedOperationException](https://docs.oracle.com/javase/7/docs/api/java/lang/UnsupportedOperationException.html)
 in  `mergeAccumulators ` since you will not call mergeAccumulators.
   
   And in the future if there is usage to call `mergeAccumulators`, the 
exception will be hit and people will know they need to implement it.




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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 461771)
    Time Spent: 20m  (was: 10m)

> Implement Navigation Functions FIRST_VALUE and LAST_VALUE
> ---------------------------------------------------------
>
>                 Key: BEAM-10551
>                 URL: https://issues.apache.org/jira/browse/BEAM-10551
>             Project: Beam
>          Issue Type: New Feature
>          Components: sdk-java-core
>            Reporter: John Mora
>            Priority: P2
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Specs:
>  
> [https://cloud.google.com/bigquery/docs/reference/standard-sql/navigation_functions#first_value]
>  
> [https://cloud.google.com/bigquery/docs/reference/standard-sql/navigation_functions#last_value]



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to