Skip to content

Commit 89def2c

Browse files
authored
Convert bool_and & bool_or to UDAF (#11009)
* Port `bool_and` and `bool_or` to `AggregateUDFImpl` * Remove trait methods with default implementation * Add `bool_or_udaf` * Register `bool_and` and `bool_or` * Remove from `physical-expr` * Add expressions to logical plan roundtrip test * minor: remove methods with default implementation * Removes redundant tests * Removes hard-coded function names
1 parent 5bfc11b commit 89def2c

File tree

16 files changed

+362
-515
lines changed

16 files changed

+362
-515
lines changed

datafusion/expr/src/aggregate_function.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ pub enum AggregateFunction {
4747
Correlation,
4848
/// Grouping
4949
Grouping,
50-
/// Bool And
51-
BoolAnd,
52-
/// Bool Or
53-
BoolOr,
5450
}
5551

5652
impl AggregateFunction {
@@ -64,8 +60,6 @@ impl AggregateFunction {
6460
NthValue => "NTH_VALUE",
6561
Correlation => "CORR",
6662
Grouping => "GROUPING",
67-
BoolAnd => "BOOL_AND",
68-
BoolOr => "BOOL_OR",
6963
}
7064
}
7165
}
@@ -82,8 +76,6 @@ impl FromStr for AggregateFunction {
8276
Ok(match name {
8377
// general
8478
"avg" => AggregateFunction::Avg,
85-
"bool_and" => AggregateFunction::BoolAnd,
86-
"bool_or" => AggregateFunction::BoolOr,
8779
"max" => AggregateFunction::Max,
8880
"mean" => AggregateFunction::Avg,
8981
"min" => AggregateFunction::Min,
@@ -128,9 +120,6 @@ impl AggregateFunction {
128120
// The coerced_data_types is same with input_types.
129121
Ok(coerced_data_types[0].clone())
130122
}
131-
AggregateFunction::BoolAnd | AggregateFunction::BoolOr => {
132-
Ok(DataType::Boolean)
133-
}
134123
AggregateFunction::Correlation => {
135124
correlation_return_type(&coerced_data_types[0])
136125
}
@@ -179,10 +168,6 @@ impl AggregateFunction {
179168
.collect::<Vec<_>>();
180169
Signature::uniform(1, valid, Volatility::Immutable)
181170
}
182-
AggregateFunction::BoolAnd | AggregateFunction::BoolOr => {
183-
Signature::uniform(1, vec![DataType::Boolean], Volatility::Immutable)
184-
}
185-
186171
AggregateFunction::Avg => {
187172
Signature::uniform(1, NUMERICS.to_vec(), Volatility::Immutable)
188173
}

datafusion/expr/src/type_coercion/aggregates.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,6 @@ pub fn coerce_types(
121121
};
122122
Ok(vec![v])
123123
}
124-
AggregateFunction::BoolAnd | AggregateFunction::BoolOr => {
125-
// Refer to https://www.postgresql.org/docs/8.2/functions-aggregate.html doc
126-
// smallint, int, bigint, real, double precision, decimal, or interval.
127-
if !is_bool_and_or_support_arg_type(&input_types[0]) {
128-
return plan_err!(
129-
"The function {:?} does not support inputs of type {:?}.",
130-
agg_fun,
131-
input_types[0]
132-
);
133-
}
134-
Ok(input_types.to_vec())
135-
}
136124
AggregateFunction::Correlation => {
137125
if !is_correlation_support_arg_type(&input_types[0]) {
138126
return plan_err!(
@@ -319,10 +307,6 @@ pub fn avg_sum_type(arg_type: &DataType) -> Result<DataType> {
319307
}
320308
}
321309

322-
pub fn is_bool_and_or_support_arg_type(arg_type: &DataType) -> bool {
323-
matches!(arg_type, DataType::Boolean)
324-
}
325-
326310
pub fn is_sum_support_arg_type(arg_type: &DataType) -> bool {
327311
match arg_type {
328312
DataType::Dictionary(_, dict_value_type) => {

0 commit comments

Comments
 (0)