Skip to content

Commit

Permalink
Convert BitAnd, BitOr, BitXor to UDAF (apache#10930)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Dharan Aditya authored and findepi committed Jul 16, 2024
1 parent 6fe58c1 commit 4570b10
Show file tree
Hide file tree
Showing 15 changed files with 481 additions and 856 deletions.
20 changes: 0 additions & 20 deletions datafusion/expr/src/aggregate_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ pub enum AggregateFunction {
Correlation,
/// Grouping
Grouping,
/// Bit And
BitAnd,
/// Bit Or
BitOr,
/// Bit Xor
BitXor,
/// Bool And
BoolAnd,
/// Bool Or
Expand All @@ -72,9 +66,6 @@ impl AggregateFunction {
NthValue => "NTH_VALUE",
Correlation => "CORR",
Grouping => "GROUPING",
BitAnd => "BIT_AND",
BitOr => "BIT_OR",
BitXor => "BIT_XOR",
BoolAnd => "BOOL_AND",
BoolOr => "BOOL_OR",
StringAgg => "STRING_AGG",
Expand All @@ -94,9 +85,6 @@ impl FromStr for AggregateFunction {
Ok(match name {
// general
"avg" => AggregateFunction::Avg,
"bit_and" => AggregateFunction::BitAnd,
"bit_or" => AggregateFunction::BitOr,
"bit_xor" => AggregateFunction::BitXor,
"bool_and" => AggregateFunction::BoolAnd,
"bool_or" => AggregateFunction::BoolOr,
"max" => AggregateFunction::Max,
Expand Down Expand Up @@ -144,9 +132,6 @@ impl AggregateFunction {
// The coerced_data_types is same with input_types.
Ok(coerced_data_types[0].clone())
}
AggregateFunction::BitAnd
| AggregateFunction::BitOr
| AggregateFunction::BitXor => Ok(coerced_data_types[0].clone()),
AggregateFunction::BoolAnd | AggregateFunction::BoolOr => {
Ok(DataType::Boolean)
}
Expand Down Expand Up @@ -199,11 +184,6 @@ impl AggregateFunction {
.collect::<Vec<_>>();
Signature::uniform(1, valid, Volatility::Immutable)
}
AggregateFunction::BitAnd
| AggregateFunction::BitOr
| AggregateFunction::BitXor => {
Signature::uniform(1, INTEGERS.to_vec(), Volatility::Immutable)
}
AggregateFunction::BoolAnd | AggregateFunction::BoolOr => {
Signature::uniform(1, vec![DataType::Boolean], Volatility::Immutable)
}
Expand Down
18 changes: 0 additions & 18 deletions datafusion/expr/src/type_coercion/aggregates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,6 @@ pub fn coerce_types(
};
Ok(vec![v])
}
AggregateFunction::BitAnd
| AggregateFunction::BitOr
| AggregateFunction::BitXor => {
// Refer to https://www.postgresql.org/docs/8.2/functions-aggregate.html doc
// smallint, int, bigint, real, double precision, decimal, or interval.
if !is_bit_and_or_xor_support_arg_type(&input_types[0]) {
return plan_err!(
"The function {:?} does not support inputs of type {:?}.",
agg_fun,
input_types[0]
);
}
Ok(input_types.to_vec())
}
AggregateFunction::BoolAnd | AggregateFunction::BoolOr => {
// Refer to https://www.postgresql.org/docs/8.2/functions-aggregate.html doc
// smallint, int, bigint, real, double precision, decimal, or interval.
Expand Down Expand Up @@ -350,10 +336,6 @@ pub fn avg_sum_type(arg_type: &DataType) -> Result<DataType> {
}
}

pub fn is_bit_and_or_xor_support_arg_type(arg_type: &DataType) -> bool {
NUMERICS.contains(arg_type)
}

pub fn is_bool_and_or_support_arg_type(arg_type: &DataType) -> bool {
matches!(arg_type, DataType::Boolean)
}
Expand Down
Loading

0 comments on commit 4570b10

Please sign in to comment.