Skip to content

feat(sql): add bit_and(), bit_or(), and bit_xor() aggregate functions#6660

Merged
bluestreak01 merged 2 commits intomasterfrom
vi_bit
Jan 18, 2026
Merged

feat(sql): add bit_and(), bit_or(), and bit_xor() aggregate functions#6660
bluestreak01 merged 2 commits intomasterfrom
vi_bit

Conversation

@bluestreak01
Copy link
Copy Markdown
Member

Summary

  • Add bit_and() aggregate function - returns bitwise AND of all non-null values
  • Add bit_or() aggregate function - returns bitwise OR of all non-null values
  • Add bit_xor() aggregate function - returns bitwise XOR of all non-null values

All functions support byte, short, int, and long column types.

Features

  • Proper null handling (nulls are skipped, similar to other aggregate functions)
  • Constant folding optimization in factories
  • Parallel execution support via merge() method
  • Returns null for empty tables or all-null inputs

Usage Examples

-- Basic usage
SELECT bit_and(flags) FROM events;
SELECT bit_or(permissions) FROM users;
SELECT bit_xor(checksum) FROM data;

-- With GROUP BY
SELECT category, bit_and(status_flags) FROM items GROUP BY category;

Test plan

  • Basic tests for all types (byte, short, int, long)
  • Null handling tests
  • Empty table tests
  • All-null value tests
  • GROUP BY tests
  • Constant argument tests
  • Parallel execution tests with WorkerPool (4 workers, 100K rows)
  • Parallel execution tests with null values interspersed

🤖 Generated with Claude Code

Implement bitwise aggregate functions for byte, short, int, and long data types:

- bit_and(column): Returns the bitwise AND of all non-null values
- bit_or(column): Returns the bitwise OR of all non-null values
- bit_xor(column): Returns the bitwise XOR of all non-null values

Features:
- Support for byte, short, int, and long column types
- Proper null handling (nulls are skipped)
- Constant folding optimization in factories
- Parallel execution support via merge() method
- Returns null for empty tables or all-null inputs

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 16, 2026

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 418 / 484 (86.36%)

file detail

path covered line new line coverage
🔵 io/questdb/griffin/engine/functions/groupby/BitOrByteGroupByFunction.java 20 27 74.07%
🔵 io/questdb/griffin/engine/functions/groupby/BitAndShortGroupByFunction.java 20 27 74.07%
🔵 io/questdb/griffin/engine/functions/groupby/BitAndByteGroupByFunction.java 20 27 74.07%
🔵 io/questdb/griffin/engine/functions/groupby/BitXorByteGroupByFunction.java 20 27 74.07%
🔵 io/questdb/griffin/engine/functions/groupby/BitOrShortGroupByFunction.java 20 27 74.07%
🔵 io/questdb/griffin/engine/functions/groupby/BitXorShortGroupByFunction.java 20 27 74.07%
🔵 io/questdb/griffin/engine/functions/groupby/BitAndIntGroupByFunctionFactory.java 9 10 90.00%
🔵 io/questdb/griffin/engine/functions/groupby/BitOrIntGroupByFunctionFactory.java 9 10 90.00%
🔵 io/questdb/griffin/engine/functions/groupby/BitXorIntGroupByFunctionFactory.java 9 10 90.00%
🔵 io/questdb/griffin/engine/functions/groupby/BitXorLongGroupByFunctionFactory.java 9 10 90.00%
🔵 io/questdb/griffin/engine/functions/groupby/BitOrLongGroupByFunctionFactory.java 9 10 90.00%
🔵 io/questdb/griffin/engine/functions/groupby/BitAndLongGroupByFunctionFactory.java 9 10 90.00%
🔵 io/questdb/griffin/engine/functions/groupby/BitXorIntGroupByFunction.java 32 35 91.43%
🔵 io/questdb/griffin/engine/functions/groupby/BitOrIntGroupByFunction.java 32 35 91.43%
🔵 io/questdb/griffin/engine/functions/groupby/BitAndIntGroupByFunction.java 33 36 91.67%
🔵 io/questdb/griffin/engine/functions/groupby/BitOrLongGroupByFunction.java 35 38 92.11%
🔵 io/questdb/griffin/engine/functions/groupby/BitXorLongGroupByFunction.java 35 38 92.11%
🔵 io/questdb/griffin/engine/functions/groupby/BitAndLongGroupByFunction.java 35 38 92.11%
🔵 io/questdb/griffin/engine/functions/groupby/BitXorByteGroupByFunctionFactory.java 7 7 100.00%
🔵 io/questdb/griffin/engine/functions/groupby/BitAndShortGroupByFunctionFactory.java 7 7 100.00%
🔵 io/questdb/griffin/engine/functions/groupby/BitOrShortGroupByFunctionFactory.java 7 7 100.00%
🔵 io/questdb/griffin/engine/functions/groupby/BitXorShortGroupByFunctionFactory.java 7 7 100.00%
🔵 io/questdb/griffin/engine/functions/groupby/BitAndByteGroupByFunctionFactory.java 7 7 100.00%
🔵 io/questdb/griffin/engine/functions/groupby/BitOrByteGroupByFunctionFactory.java 7 7 100.00%

@bluestreak01 bluestreak01 added New feature Feature requests SQL Issues or changes relating to SQL execution labels Jan 18, 2026
@bluestreak01 bluestreak01 merged commit 97453b6 into master Jan 18, 2026
43 checks passed
@bluestreak01 bluestreak01 deleted the vi_bit branch January 18, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New feature Feature requests SQL Issues or changes relating to SQL execution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants