[
https://issues.apache.org/jira/browse/BEAM-11389?focusedWorklogId=553718&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-553718
]
ASF GitHub Bot logged work on BEAM-11389:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 17/Feb/21 16:37
Start Date: 17/Feb/21 16:37
Worklog Time Spent: 10m
Work Description: 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]
Issue Time Tracking
-------------------
Worklog Id: (was: 553718)
Time Spent: 2h 50m (was: 2h 40m)
> Implement the LOGICAL_AND function for Beam SQL ZetaSQL dialect, as CombineFn.
> ------------------------------------------------------------------------------
>
> Key: BEAM-11389
> URL: https://issues.apache.org/jira/browse/BEAM-11389
> Project: Beam
> Issue Type: Sub-task
> Components: dsl-sql-zetasql
> Reporter: Sonam Ramchand
> Priority: P2
> Time Spent: 2h 50m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)