Uploaded image for project: 'Beam'
  1. Beam
  2. BEAM-10379

Some problems when implementing BIT_AND aggregation function in BeamSQL

    XMLWordPrintableJSON

    Details

    • Type: Task
    • Status: Open
    • Priority: P2
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: dsl-sql, dsl-sql-zetasql
    • Labels:

      Description

      Performs a bitwise AND operation on expression and returns the result.

      Supported Argument Types: INT64
      Returned Data Types: INT64

      Examples

      SELECT BIT_AND(c) as bit_and FROM UNNEST([0xF001, 0x00A1]) as c;
      
      +---------+
      | bit_and |
      +---------+
      | 1       |
      +---------+
      

       

      What is expected: should include both Calcite and ZetaSQL dialects.

      How to test: unit tests

      Reference: https://cloud.google.com/bigquery/docs/reference/standard-sql/aggregate_functions#bit_and

       

      Problems: 

      After implementation, the current situation is:
      1. When table is empty, the result is empty, correct.

      2. When table contains only null values, the result is null, correct.

      3. When table contains only valid numerical values, the result is as expected, correct.

      4. When table contains both valid numerical values and null values, the result should be null (BitAnd(null, val) = null). But it seems all null values have been directly ignored before doing the bit_and operation. Only numerical values are taken into operation, so the result is incorrect.

       
      It turns out that on direct runner, NULL will not be passed to CombineFn thus all NULL inputs are ignored. And then if there is any non-null inputs, bit_and will be applied on them only, which leads to a non-null result, which is not correct.

      Before figuring out the root cause and proposing a fix, the previous implementation of BIT_AND is reverted.
       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                fuyuwei Yuwei Fu
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10m
                  10m