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

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

                Author: ASF GitHub Bot
            Created on: 13/Jan/21 19:24
            Start Date: 13/Jan/21 19:24
    Worklog Time Spent: 10m 
      Work Description: ibzib commented on a change in pull request #13745:
URL: https://github.com/apache/beam/pull/13745#discussion_r556773137



##########
File path: 
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/transform/BeamBuiltinAggregations.java
##########
@@ -397,40 +397,54 @@ public Long extractOutput(Long accum) {
    * <p>Note: null values are ignored when mixed with non-null values.
    * (https://issues.apache.org/jira/browse/BEAM-10379)
    */
-  static class BitAnd<T extends Number> extends CombineFn<T, Long, Long> {
-    // Indicate if input only contains null value.
-    private boolean isEmpty = true;
+  static class BitAnd<T extends Number> extends CombineFn<T, BitAnd.Accum, 
Long> {
+    static class Accum {
+      /** True if no inputs have been seen yet. */
+      boolean isEmpty = true;
+      /** True if any null inputs have been seen. */
+      boolean isNull = false;
+      /** The bitwise-and of the inputs seen so far. */
+      long bitAnd = -1L;
+    }
 
     @Override
-    public Long createAccumulator() {
-      return -1L;
+    public Accum createAccumulator() {
+      return new Accum();
     }
 
     @Override
-    public Long addInput(Long accum, T input) {
-      if (input != null) {
-        this.isEmpty = false;
-        return accum & input.longValue();
-      } else {
-        return null;
+    public Accum addInput(Accum accum, T input) {
+      if (input == null) {

Review comment:
       It's not strictly necessary, but I added it for clarity.




----------------------------------------------------------------
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: 535651)
    Time Spent: 40m  (was: 0.5h)

> BitAnd unsafely mutates an instance field.
> ------------------------------------------
>
>                 Key: BEAM-11637
>                 URL: https://issues.apache.org/jira/browse/BEAM-11637
>             Project: Beam
>          Issue Type: Bug
>          Components: dsl-sql
>            Reporter: Kyle Weaver
>            Assignee: Kyle Weaver
>            Priority: P2
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> BitAnd uses isEmpty, an instance field, to track if inputs seen thus far are 
> null. This is an unsafe usage of CombineFn, since all mutable state is 
> expected to be stored in the Accumulator.



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

Reply via email to