Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions datafusion/functions-aggregate/src/bit_and_or_xor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ impl AggregateUDFImpl for BitwiseOperation {
}
}

fn groups_accumulator_supported(&self, _args: AccumulatorArgs) -> bool {
true
fn groups_accumulator_supported(&self, args: AccumulatorArgs) -> bool {
!args.is_distinct

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we limit operator to XOR only, since AND and OR are idempotent so DISTINCT does not change their result and they keep the vectorized path.

Also, do we need to handle null case? This could be a follow-up issue

Suggested change
!args.is_distinct
!(args.is_distinct && self.operation == BitwiseOperationType::Xor)

}

fn create_groups_accumulator(
Expand Down
22 changes: 22 additions & 0 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -5123,6 +5123,28 @@ ORDER BY tag
33 11 NULL 33 11 NULL 33 11 NULL B


# bit_xor(DISTINCT) with GROUP BY must not use the non-distinct groups
# accumulator: for tag A, 5 ^ 5 ^ 9 = 9 but 5 ^ 9 = 12.
statement ok
create table bit_distinct (c SMALLINT, tag varchar) as values
(5, 'A'), (5, 'A'), (9, 'A'), (33, 'B'), (33, 'B');

query IIT
SELECT bit_xor(DISTINCT c), count(c), tag FROM bit_distinct GROUP BY tag ORDER BY tag;
----
12 3 A
33 2 B

query IT
SELECT bit_xor(DISTINCT c) FILTER (WHERE c > 4), tag FROM bit_distinct GROUP BY tag ORDER BY tag;
----
12 A
33 B

statement ok
drop table bit_distinct;


# bit_and_i32
statement ok
create table t (c int) as values (4), (7), (15);
Expand Down