sonam-vend commented on a change in pull request #13817:
URL: https://github.com/apache/beam/pull/13817#discussion_r577763864
##########
File path:
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/transform/BeamBuiltinAggregations.java
##########
@@ -495,4 +504,70 @@ public Long extractOutput(Long accumulator) {
return accumulator;
}
}
+ /**
+ * Logical_And function implementation
+ *
+ * <p>Returns the logical AND of all non-NULL expressions. Returns NULL if
there are zero input
+ * rows or expression evaluates to NULL for all rows.
+ */
+ 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 = true;
+ }
+
+ @Override
+ public Accum createAccumulator() {
+ return new Accum();
+ }
+
+ @Override
+ public Accum addInput(Accum accum, Boolean input) {
+ if (input == null) {
+ accum.isNull = true;
+ return accum;
+ }
+ accum.isEmpty = false;
+ accum.isNull = false;
+ accum.logicalAnd = (accum.logicalAnd && input);
+ return accum;
+ }
+
+ @Override
+ public Accum mergeAccumulators(Iterable<Accum> accums) {
+ LogicalAnd.Accum merged = createAccumulator();
+
+ /** merged accum has isNull=true when all accums have isNull=true */
+ if (StreamSupport.stream(accums.spliterator(), false).allMatch(a ->
a.isNull)) {
+ merged.isNull = true;
+ return merged;
Review comment:
@ibzib @robinyqiu this is where I am trying to return _null only if
all_ input values are null.
----------------------------------------------------------------
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]