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 2021/02/17 01:20:43 UTC

[GitHub] [beam] robinyqiu commented on a change in pull request #13817: [BEAM-11389] Implement LOGICAL_AND as CombineFn ZetaSQL

robinyqiu commented on a change in pull request #13817:
URL: https://github.com/apache/beam/pull/13817#discussion_r577258736



##########
File path: sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/transform/BeamBuiltinAggregations.java
##########
@@ -453,4 +462,57 @@ public Long extractOutput(Accum accum) {
       return accum.bitAnd;
     }
   }
+
+  public static class LogicalAnd extends CombineFn<Boolean, LogicalAnd.Accum, Boolean> {
+    static class Accum {
+      // Initially, input is empty
+      boolean isEmpty = true;
+      // true if any null value is seen in the input, null values are to be ignored
+      boolean isNull = false;
+      // logical_and operation result
+      boolean logicalAnd = Boolean.parseBoolean(null);
+    }
+
+    @Override
+    public Accum createAccumulator() {
+      return new Accum();
+    }
+
+    @Override
+    public Accum addInput(Accum accum, Boolean input) {
+      if (input == null) {
+        accum.isNull = true;
+        accum.isEmpty = false;
+        return accum;
+      }
+      accum.isEmpty = false;
+      accum.logicalAnd = accum.logicalAnd && input;
+      return accum;
+    }
+
+    @Override
+    public Accum mergeAccumulators(Iterable<Accum> accums) {
+      LogicalAnd.Accum merged = createAccumulator();
+      for (LogicalAnd.Accum accum : accums) {
+        if (accum.isNull) {
+          // ignore null case
+          continue;

Review comment:
       Hi @sonam-vend, please see the comment above to fix the problem.




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