sonam-vend commented on a change in pull request #13817:
URL: https://github.com/apache/beam/pull/13817#discussion_r577573414



##########
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:
       @ibzib @robinyqiu I consider there is a difference between logical_And 
and bit_And implementation when it comes to handling null values.  What I am 
actually trying to do is to ignore all the null values in the input. For 
instance,
   Input: [true, null, false]
   I want to ignore null value in the input and perform logical_And and for 
[true, false].




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