-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Stop copying LogicalPlan and Exprs in ReplaceDistinctWithAggregate
#10460
Stop copying LogicalPlan and Exprs in ReplaceDistinctWithAggregate
#10460
Conversation
Signed-off-by: cailue <cailue@bupt.edu.cn>
Signed-off-by: 蔡略 <cailue@bupt.edu.cn>
let aggr_expr = normalize_cols(aggr_expr, input.as_ref())?; | ||
let group_expr = normalize_cols(on_expr, input.as_ref())?; |
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.
maybe unnecessary?
let aggr_expr = select_expr | ||
.iter() | ||
.map(|e| { | ||
Expr::AggregateFunction(AggregateFunction::new( | ||
AggregateFunctionFunc::FirstValue, | ||
vec![e.clone()], | ||
false, | ||
None, | ||
sort_expr.clone(), | ||
None, | ||
)) | ||
}) | ||
.collect::<Vec<Expr>>(); | ||
let aggr_expr = vec![Expr::AggregateFunction(AggregateFunction::new( | ||
AggregateFunctionFunc::FirstValue, | ||
select_expr, | ||
false, | ||
None, | ||
sort_expr.clone(), | ||
None, | ||
))]; |
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 don't know if they are semantically identical.
Instructions welcomed.
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.
CI failed, i guess the answer is no. :(
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 difference is that the select_expr.iter()...
makes a vec
with the same number of elements as select_expr
To avoid a clone, perhaps you can use into_iter
instead of iter
, like
let aggr_expr = select_expr
.into_iter() // <---- Use into_iter() here
.map(|e| {
Expr::AggregateFunction(AggregateFunction::new(
AggregateFunctionFunc::FirstValue,
vec![e], // <--- to avoid a clone here
false,
None,
sort_expr.clone(),
None,
))
})
.collect::<Vec<Expr>>();
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 difference is that the
select_expr.iter()...
makes avec
with the same number of elements asselect_expr
To avoid a clone, perhaps you can use
into_iter
instead ofiter
, likelet aggr_expr = select_expr .into_iter() // <---- Use into_iter() here .map(|e| { Expr::AggregateFunction(AggregateFunction::new( AggregateFunctionFunc::FirstValue, vec![e], // <--- to avoid a clone here false, None, sort_expr.clone(), None, )) }) .collect::<Vec<Expr>>();
What bothers me most is that I cannot avoid cloning sort_expr
. However, it looks like the only way to make it correct.
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 pretty cool @ClSlaid -- thank you 🙏
Signed-off-by: 蔡略 <cailue@bupt.edu.cn>
ReplaceDistinctWithAggregate
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 @ClSlaid -- this is looking close.
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 reviewed this PR and I think it looks very nice to me @ClSlaid . Thank you
Also thank you for the suggestion about LogicalPlanBuilder -- perhaps you would be willing to do a follow on (to implement #10485 and then switch this code to use it)?
https://github.com/apache/datafusion/pull/10460/files#r1598480059
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 took the liberty of adding a comment to this pr and merging up from main. I plan to merge when it passes CI
THanks again @ClSlaid
…pache#10460) * patch: implement rewrite for RDWA Signed-off-by: cailue <cailue@bupt.edu.cn> * refactor: rewrite replace_distinct_aggregate Signed-off-by: 蔡略 <cailue@bupt.edu.cn> * patch: recorrect aggr_expr Signed-off-by: 蔡略 <cailue@bupt.edu.cn> * Update datafusion/optimizer/src/replace_distinct_aggregate.rs --------- Signed-off-by: cailue <cailue@bupt.edu.cn> Signed-off-by: 蔡略 <cailue@bupt.edu.cn> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Which issue does this PR close?
Closes #10293.
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?