-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: support bitwise and boolean aggregate functions #6276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alamb
merged 10 commits into
apache:main
from
izveigor:bitwise_boolean_aggregate_functions
May 15, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b972e42
feat: bitwise and boolean aggregate functions
izveigor 4ab0619
feat: SQL implementation
izveigor 8ad42aa
feat: proto
izveigor fece4bf
fix: import modules in proto
izveigor 25c8cab
fix: sqllogictests
izveigor b85fcef
feat: docs
izveigor e713457
fix: clippy
izveigor dbd8389
refactor: bit_and_or_xor.rs and bool_and_or.rs
izveigor d29754b
feat: macro_rules for bitwise aggregate operations
izveigor c8b0f3d
feat: bitwise aggregate functions in pg_compat
izveigor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,24 @@ SELECT avg(c12) FROM aggregate_test_100 | |
| ---- | ||
| 0.508972509913 | ||
|
|
||
| # csv_query_bit_and | ||
| query IIIII | ||
| SELECT bit_and(c5), bit_and(c6), bit_and(c7), bit_and(c8), bit_and(c9) FROM aggregate_test_100 | ||
| ---- | ||
| 0 0 0 0 0 | ||
|
|
||
| # csv_query_bit_or | ||
| query IIIII | ||
| SELECT bit_or(c5), bit_or(c6), bit_or(c7), bit_or(c8), bit_or(c9) FROM aggregate_test_100 | ||
| ---- | ||
| -1 -1 255 65535 4294967295 | ||
|
|
||
| # csv_query_bit_xor | ||
| query IIIII | ||
| SELECT bit_xor(c5), bit_xor(c6), bit_xor(c7), bit_xor(c8), bit_xor(c9) FROM aggregate_test_100 | ||
| ---- | ||
| 1632751011 5960911605712039654 148 54789 169634700 | ||
|
|
||
| # csv_query_covariance_1 | ||
| query R | ||
| SELECT covar_pop(c2, c12) FROM aggregate_test_100 | ||
|
|
@@ -1355,6 +1373,27 @@ SELECT avg(column1), column2 from the_nulls group by column2 order by column2; | |
| NULL 1 | ||
| NULL 2 | ||
|
|
||
| # bit_and should be null | ||
| query II | ||
| SELECT bit_and(column1), column2 from the_nulls group by column2 order by column2; | ||
| ---- | ||
| NULL 1 | ||
| NULL 2 | ||
|
|
||
| # bit_or should be null | ||
| query II | ||
| SELECT bit_or(column1), column2 from the_nulls group by column2 order by column2; | ||
| ---- | ||
| NULL 1 | ||
| NULL 2 | ||
|
|
||
| # bit_xor should be null | ||
| query II | ||
| SELECT bit_xor(column1), column2 from the_nulls group by column2 order by column2; | ||
| ---- | ||
| NULL 1 | ||
| NULL 2 | ||
|
|
||
| # min should be null | ||
| query II | ||
| SELECT min(column1), column2 from the_nulls group by column2 order by column2; | ||
|
|
@@ -1390,6 +1429,63 @@ as values | |
| ('2021-01-01T05:11:10.432', 'Row 3'); | ||
|
|
||
|
|
||
| statement ok | ||
| create table bit_aggregate_functions ( | ||
| c1 SMALLINT NOT NULL, | ||
| c2 SMALLINT NOT NULL, | ||
| c3 SMALLINT, | ||
| ) | ||
| as values | ||
| (5, 10, 11), | ||
| (33, 11, null), | ||
| (9, 12, null); | ||
|
|
||
| # query_bit_and | ||
| query III | ||
| SELECT bit_and(c1), bit_and(c2), bit_and(c3) FROM bit_aggregate_functions | ||
| ---- | ||
| 1 8 11 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I double checked this is consistent with postgres 👍 |
||
|
|
||
| # query_bit_or | ||
| query III | ||
| SELECT bit_or(c1), bit_or(c2), bit_or(c3) FROM bit_aggregate_functions | ||
| ---- | ||
| 45 15 11 | ||
|
|
||
| # query_bit_xor | ||
| query III | ||
| SELECT bit_xor(c1), bit_xor(c2), bit_xor(c3) FROM bit_aggregate_functions | ||
| ---- | ||
| 45 13 11 | ||
|
|
||
| statement ok | ||
| create table bool_aggregate_functions ( | ||
| c1 boolean not null, | ||
| c2 boolean not null, | ||
| c3 boolean not null, | ||
| c4 boolean not null, | ||
| c5 boolean, | ||
| c6 boolean, | ||
| c7 boolean, | ||
| c8 boolean, | ||
| ) | ||
| as values | ||
| (true, true, false, false, true, true, null, null), | ||
| (true, false, true, false, false, null, false, null), | ||
| (true, true, false, false, null, true, false, null); | ||
|
|
||
| # query_bool_and | ||
| query BBBBBBBB | ||
| SELECT bool_and(c1), bool_and(c2), bool_and(c3), bool_and(c4), bool_and(c5), bool_and(c6), bool_and(c7), bool_and(c8) FROM bool_aggregate_functions | ||
| ---- | ||
| true false false false false true false NULL | ||
|
|
||
| # query_bool_or | ||
| query BBBBBBBB | ||
| SELECT bool_or(c1), bool_or(c2), bool_or(c3), bool_or(c4), bool_or(c5), bool_or(c6), bool_or(c7), bool_or(c8) FROM bool_aggregate_functions | ||
| ---- | ||
| true true true false true true false NULL | ||
|
|
||
| statement ok | ||
| create table t as | ||
| select | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given postgres also runs these queries what do you think about also adding them into a
pg_compattest in https://github.com/apache/arrow-datafusion/tree/main/datafusion/core/tests/sqllogictests/test_files/pg_compat?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a nice idea for bitwise aggregate functions.