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

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

                Author: ASF GitHub Bot
            Created on: 29/Apr/20 18:27
            Start Date: 29/Apr/20 18:27
    Worklog Time Spent: 10m 
      Work Description: amaliujia commented on a change in pull request #11333:
URL: https://github.com/apache/beam/pull/11333#discussion_r417519797



##########
File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Sample.java
##########
@@ -58,6 +58,14 @@
     return new SampleAnyCombineFn<>(sampleSize);
   }
 
+  /**
+   * Returns a {@link CombineFn} that computes a single and potentially 
non-uniform sample value of
+   * its inputs.
+   */
+  public static <T> CombineFn<T, ?, T> anyValueCombineFn() {

Review comment:
       Why `?` as a part of template? (just asking. I am not familiar with how 
it should be used)

##########
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:
       I think this is right to return a null. 
   
   per [1], if empty or input rows are all null, return null.
   
   Though returning `null` in Java sometimes do causing problems (not the 
problem in SQL layer, but in Java world). But in BeamSQL we just did it so far.
   
   
   [1]: 
https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#any_value




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


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

    Worklog Id:     (was: 428695)
    Time Spent: 2h  (was: 1h 50m)

> Support ANY_VALUE aggregation functions
> ---------------------------------------
>
>                 Key: BEAM-9418
>                 URL: https://issues.apache.org/jira/browse/BEAM-9418
>             Project: Beam
>          Issue Type: Task
>          Components: dsl-sql
>            Reporter: Rui Wang
>            Assignee: John Mora
>            Priority: Major
>          Time Spent: 2h
>  Remaining Estimate: 0h
>
> Support the following functionality in BeamSQL:
> {code:java}
> "select t.key, ANY_VALUE(t.column) from t group by t.key";
> {code}
> Spec link: 
> https://cloud.google.com/bigquery/docs/reference/standard-sql/aggregate_functions#any_value



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

Reply via email to