-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Refactor aggregate function handling #8358
Conversation
cb469eb
to
95a868f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Weijun-H -- this looks great. I had some code style suggestion that could reduce duplication but I don't think they are necessary as the duplication already exists and we could potentially do it as a follow on (though this PR would be stronger 🦾 if they were done too)
It looks like there are some conflicts to resolve
But all in all, great work and thank you
let mut names = Vec::with_capacity(args.len()); | ||
for e in args { | ||
names.push(create_physical_name(e, false)?); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it is the same as was here, but I think you can write this more concisely like
let mut names = Vec::with_capacity(args.len()); | |
for e in args { | |
names.push(create_physical_name(e, false)?); | |
} | |
let names = args.iter() | |
.map(|e| create_physical_name(e, false)) | |
.collect::<Result<Vec<_>>()? |
)?), | ||
None => None, | ||
}; | ||
let order_by = match order_by { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be possible to do the order_by and filter conversions once rather than for both arms
datafusion/expr/src/expr.rs
Outdated
@@ -477,11 +475,36 @@ impl Sort { | |||
} | |||
} | |||
|
|||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | |||
/// Defines which implementation of a function for DataFusion to call. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Defines which implementation of a function for DataFusion to call. | |
/// Defines which implementation of an aggregate function DataFusion should call. |
datafusion/expr/src/expr.rs
Outdated
fun: aggregate_function::AggregateFunction, | ||
name: Arc<str>, | ||
}, | ||
/// Resolved to a user defined function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Resolved to a user defined function | |
/// Resolved to a user defined aggregate function |
datafusion/expr/src/expr.rs
Outdated
}) => match func_def { | ||
AggregateFunctionDefinition::BuiltIn { fun: _, name: _ } | ||
| AggregateFunctionDefinition::Name(_) => { | ||
let mut name = create_function_name(func_def.name(), *distinct, args)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to combine the arms together here (the AggregateFunctionDefinition::UDF
appears to do the same thing, though I realize it is not entirely the same)
datafusion/expr/src/expr_schema.rs
Outdated
Expr::AggregateFunction(AggregateFunction { func_def, args, .. }) => { | ||
match func_def { | ||
AggregateFunctionDefinition::BuiltIn { fun, .. } => { | ||
let data_types = args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data_types calculation could be hoisted above as well
95a868f
to
99273de
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great -- thanks again @Weijun-H
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
/// Defines which implementation of an aggregate function DataFusion should call. | ||
pub enum AggregateFunctionDefinition { | ||
BuiltIn(aggregate_function::AggregateFunction), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Since this is an API change I will leave it open for another day before merging. Really nice work @Weijun-H |
1fb0b0c
to
3da4d54
Compare
3da4d54
to
441ca13
Compare
Thanks again @Weijun-H -- this is really nice |
Which issue does this PR close?
Closes #8346
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?