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
5 changes: 3 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,9 @@ impl AggregateUDFImpl for BitwiseOperation {
}
}

fn groups_accumulator_supported(&self, _args: AccumulatorArgs) -> bool {
true
fn groups_accumulator_supported(&self, args: AccumulatorArgs) -> bool {
// DISTINCT only changes the result of XOR; AND and OR are idempotent
!(args.is_distinct && self.operation == BitwiseOperationType::Xor)
}

fn create_groups_accumulator(
Expand Down
29 changes: 29 additions & 0 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -5123,6 +5123,35 @@ 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. AND and OR are
# idempotent, so they keep the groups accumulator.
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

query IIIT
SELECT bit_and(DISTINCT c), bit_or(DISTINCT c), count(c), tag FROM bit_distinct GROUP BY tag ORDER BY tag;
----
1 13 3 A
33 33 2 B

statement ok
drop table bit_distinct;


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