Skip to content

Minor: Add Accumulator::return_type and StateFieldsArgs::return_type to help with upgrade to 48 #16112

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion datafusion-examples/examples/advanced_udaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl AggregateUDFImpl for GeoMeanUdaf {
/// This is the description of the state. accumulator's state() must match the types here.
fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<Field>> {
Ok(vec![
Field::new("prod", args.return_field.data_type().clone(), true),
Field::new("prod", args.return_type().clone(), true),
Field::new("n", DataType::UInt32, true),
])
}
Expand Down
7 changes: 7 additions & 0 deletions datafusion/functions-aggregate-common/src/accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,10 @@ pub struct StateFieldsArgs<'a> {
/// Whether the aggregate function is distinct.
pub is_distinct: bool,
}

impl StateFieldsArgs<'_> {
/// The return type of the aggregate function.
pub fn return_type(&self) -> &DataType {
self.return_field.data_type()
}
}
2 changes: 1 addition & 1 deletion datafusion/functions-aggregate/src/bit_and_or_xor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl AggregateUDFImpl for BitwiseOperation {
format!("{} distinct", self.name()).as_str(),
),
// See COMMENTS.md to understand why nullable is set to true
Field::new_list_field(args.return_field.data_type().clone(), true),
Field::new_list_field(args.return_type().clone(), true),
false,
)])
} else {
Expand Down
2 changes: 1 addition & 1 deletion datafusion/functions-aggregate/src/first_last.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl AggregateUDFImpl for FirstValue {
fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<Field>> {
let mut fields = vec![Field::new(
format_state_name(args.name, "first_value"),
args.return_field.data_type().clone(),
args.return_type().clone(),
true,
)];
fields.extend(args.ordering_fields.to_vec());
Expand Down
4 changes: 2 additions & 2 deletions datafusion/functions-aggregate/src/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ impl AggregateUDFImpl for Sum {
Ok(vec![Field::new_list(
format_state_name(args.name, "sum distinct"),
// See COMMENTS.md to understand why nullable is set to true
Field::new_list_field(args.return_field.data_type().clone(), true),
Field::new_list_field(args.return_type().clone(), true),
false,
)])
} else {
Ok(vec![Field::new(
format_state_name(args.name, "sum"),
args.return_field.data_type().clone(),
args.return_type().clone(),
true,
)])
}
Expand Down