Skip to content

Commit 2daadb7

Browse files
author
Dharan Aditya
authored
Convert BitAnd, BitOr, BitXor to UDAF (#10930)
* remove bit and or xor from expr * remove bit and or xor from physical expr and proto * add proto regen changes * impl BitAnd, BitOr, BitXor UADF * add support for float * removing support for float * refactor helper macros * clippy'fy * simplify Bitwise operation * add documentation * formatting * fix lint issue * remove XorDistinct * update roundtrip_expr_api test * linting * support groups accumulator
1 parent a923c65 commit 2daadb7

File tree

15 files changed

+481
-856
lines changed

15 files changed

+481
-856
lines changed

datafusion/expr/src/aggregate_function.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ pub enum AggregateFunction {
4747
Correlation,
4848
/// Grouping
4949
Grouping,
50-
/// Bit And
51-
BitAnd,
52-
/// Bit Or
53-
BitOr,
54-
/// Bit Xor
55-
BitXor,
5650
/// Bool And
5751
BoolAnd,
5852
/// Bool Or
@@ -72,9 +66,6 @@ impl AggregateFunction {
7266
NthValue => "NTH_VALUE",
7367
Correlation => "CORR",
7468
Grouping => "GROUPING",
75-
BitAnd => "BIT_AND",
76-
BitOr => "BIT_OR",
77-
BitXor => "BIT_XOR",
7869
BoolAnd => "BOOL_AND",
7970
BoolOr => "BOOL_OR",
8071
StringAgg => "STRING_AGG",
@@ -94,9 +85,6 @@ impl FromStr for AggregateFunction {
9485
Ok(match name {
9586
// general
9687
"avg" => AggregateFunction::Avg,
97-
"bit_and" => AggregateFunction::BitAnd,
98-
"bit_or" => AggregateFunction::BitOr,
99-
"bit_xor" => AggregateFunction::BitXor,
10088
"bool_and" => AggregateFunction::BoolAnd,
10189
"bool_or" => AggregateFunction::BoolOr,
10290
"max" => AggregateFunction::Max,
@@ -144,9 +132,6 @@ impl AggregateFunction {
144132
// The coerced_data_types is same with input_types.
145133
Ok(coerced_data_types[0].clone())
146134
}
147-
AggregateFunction::BitAnd
148-
| AggregateFunction::BitOr
149-
| AggregateFunction::BitXor => Ok(coerced_data_types[0].clone()),
150135
AggregateFunction::BoolAnd | AggregateFunction::BoolOr => {
151136
Ok(DataType::Boolean)
152137
}
@@ -199,11 +184,6 @@ impl AggregateFunction {
199184
.collect::<Vec<_>>();
200185
Signature::uniform(1, valid, Volatility::Immutable)
201186
}
202-
AggregateFunction::BitAnd
203-
| AggregateFunction::BitOr
204-
| AggregateFunction::BitXor => {
205-
Signature::uniform(1, INTEGERS.to_vec(), Volatility::Immutable)
206-
}
207187
AggregateFunction::BoolAnd | AggregateFunction::BoolOr => {
208188
Signature::uniform(1, vec![DataType::Boolean], Volatility::Immutable)
209189
}

datafusion/expr/src/type_coercion/aggregates.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,6 @@ pub fn coerce_types(
121121
};
122122
Ok(vec![v])
123123
}
124-
AggregateFunction::BitAnd
125-
| AggregateFunction::BitOr
126-
| AggregateFunction::BitXor => {
127-
// Refer to https://www.postgresql.org/docs/8.2/functions-aggregate.html doc
128-
// smallint, int, bigint, real, double precision, decimal, or interval.
129-
if !is_bit_and_or_xor_support_arg_type(&input_types[0]) {
130-
return plan_err!(
131-
"The function {:?} does not support inputs of type {:?}.",
132-
agg_fun,
133-
input_types[0]
134-
);
135-
}
136-
Ok(input_types.to_vec())
137-
}
138124
AggregateFunction::BoolAnd | AggregateFunction::BoolOr => {
139125
// Refer to https://www.postgresql.org/docs/8.2/functions-aggregate.html doc
140126
// smallint, int, bigint, real, double precision, decimal, or interval.
@@ -350,10 +336,6 @@ pub fn avg_sum_type(arg_type: &DataType) -> Result<DataType> {
350336
}
351337
}
352338

353-
pub fn is_bit_and_or_xor_support_arg_type(arg_type: &DataType) -> bool {
354-
NUMERICS.contains(arg_type)
355-
}
356-
357339
pub fn is_bool_and_or_support_arg_type(arg_type: &DataType) -> bool {
358340
matches!(arg_type, DataType::Boolean)
359341
}

0 commit comments

Comments
 (0)