Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ballista/rust/core/proto/ballista.proto
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ enum AggregateFunction {
COUNT = 4;
APPROX_DISTINCT = 5;
ARRAY_AGG = 6;
SET_AGG = 7;
}

message AggregateExprNode {
Expand Down
2 changes: 2 additions & 0 deletions ballista/rust/core/src/serde/logical_plan/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ impl TryInto<protobuf::LogicalExprNode> for &Expr {
protobuf::AggregateFunction::ApproxDistinct
}
AggregateFunction::ArrayAgg => protobuf::AggregateFunction::ArrayAgg,
AggregateFunction::SetAgg => protobuf::AggregateFunction::SetAgg,
AggregateFunction::Min => protobuf::AggregateFunction::Min,
AggregateFunction::Max => protobuf::AggregateFunction::Max,
AggregateFunction::Sum => protobuf::AggregateFunction::Sum,
Expand Down Expand Up @@ -1364,6 +1365,7 @@ impl From<&AggregateFunction> for protobuf::AggregateFunction {
AggregateFunction::Count => Self::Count,
AggregateFunction::ApproxDistinct => Self::ApproxDistinct,
AggregateFunction::ArrayAgg => Self::ArrayAgg,
AggregateFunction::SetAgg => Self::SetAgg,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ballista/rust/core/src/serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl From<protobuf::AggregateFunction> for AggregateFunction {
AggregateFunction::ApproxDistinct
}
protobuf::AggregateFunction::ArrayAgg => AggregateFunction::ArrayAgg,
protobuf::AggregateFunction::SetAgg => AggregateFunction::SetAgg,
}
}
}
Expand Down
16 changes: 15 additions & 1 deletion datafusion/src/physical_plan/aggregates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub enum AggregateFunction {
ApproxDistinct,
/// array_agg
ArrayAgg,
/// set_agg
SetAgg,
}

impl fmt::Display for AggregateFunction {
Expand All @@ -84,6 +86,7 @@ impl FromStr for AggregateFunction {
"sum" => AggregateFunction::Sum,
"approx_distinct" => AggregateFunction::ApproxDistinct,
"array_agg" => AggregateFunction::ArrayAgg,
"set_agg" => AggregateFunction::SetAgg,
_ => {
return Err(DataFusionError::Plan(format!(
"There is no built-in function named {}",
Expand Down Expand Up @@ -122,6 +125,11 @@ pub fn return_type(
coerced_data_types[0].clone(),
true,
)))),
AggregateFunction::SetAgg => Ok(DataType::List(Box::new(Field::new(
"item",
coerced_data_types[0].clone(),
true,
)))),
}
}

Expand Down Expand Up @@ -192,6 +200,11 @@ pub fn create_aggregate_expr(
name,
coerced_exprs_types[0].clone(),
)),
(AggregateFunction::SetAgg, _) => Arc::new(expressions::SetAgg::new(
coerced_phy_exprs[0].clone(),
name,
coerced_exprs_types[0].clone(),
)),
(AggregateFunction::Min, _) => Arc::new(expressions::Min::new(
coerced_phy_exprs[0].clone(),
name,
Expand Down Expand Up @@ -245,7 +258,8 @@ pub fn signature(fun: &AggregateFunction) -> Signature {
match fun {
AggregateFunction::Count
| AggregateFunction::ApproxDistinct
| AggregateFunction::ArrayAgg => Signature::any(1, Volatility::Immutable),
| AggregateFunction::ArrayAgg
| AggregateFunction::SetAgg => Signature::any(1, Volatility::Immutable),
AggregateFunction::Min | AggregateFunction::Max => {
let valid = STRINGS
.iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub(crate) fn coerce_types(
Ok(input_types.to_vec())
}
AggregateFunction::ArrayAgg => Ok(input_types.to_vec()),
AggregateFunction::SetAgg => Ok(input_types.to_vec()),
AggregateFunction::Min | AggregateFunction::Max => {
// min and max support the dictionary data type
// unpack the dictionary to get the value
Expand Down
2 changes: 2 additions & 0 deletions datafusion/src/physical_plan/expressions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ mod nth_value;
mod nullif;
mod rank;
mod row_number;
mod set_agg;
mod sum;
mod try_cast;

Expand Down Expand Up @@ -84,6 +85,7 @@ pub use nth_value::NthValue;
pub use nullif::{nullif_func, SUPPORTED_NULLIF_TYPES};
pub use rank::{dense_rank, percent_rank, rank};
pub use row_number::RowNumber;
pub use set_agg::SetAgg;
pub(crate) use sum::is_sum_support_arg_type;
pub use sum::{sum_return_type, Sum};
pub use try_cast::{try_cast, TryCastExpr};
Expand Down
Loading