-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add Aggregate::try new with validation checks
#3286
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,22 @@ pub fn exprlist_to_columns(expr: &[Expr], accum: &mut HashSet<Column>) -> Result | |
| Ok(()) | ||
| } | ||
|
|
||
| /// Count the number of distinct exprs in a list of group by expressions. If the | ||
| /// first element is a `GroupingSet` expression then it must be the only expr. | ||
| pub fn grouping_set_expr_count(group_expr: &[Expr]) -> Result<usize> { | ||
| if let Some(Expr::GroupingSet(grouping_set)) = group_expr.first() { | ||
| if group_expr.len() > 1 { | ||
| return Err(DataFusionError::Plan( | ||
| "Invalid group by expressions, GroupingSet must be the only expression" | ||
| .to_string(), | ||
| )); | ||
| } | ||
| Ok(grouping_set.distinct_expr().len()) | ||
| } else { | ||
| Ok(group_expr.len()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to do other validation? Should I be able to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I expect that we could add extra validation here over time. I would need to research what is allowable.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW the sqlparser won't allow |
||
| } | ||
| } | ||
|
|
||
| /// Find all distinct exprs in a list of group by expressions. If the | ||
| /// first element is a `GroupingSet` expression then it must be the only expr. | ||
| pub fn grouping_set_to_exprlist(group_expr: &[Expr]) -> Result<Vec<Expr>> { | ||
|
|
@@ -395,12 +411,12 @@ pub fn from_plan( | |
| })), | ||
| LogicalPlan::Aggregate(Aggregate { | ||
| group_expr, schema, .. | ||
| }) => Ok(LogicalPlan::Aggregate(Aggregate { | ||
| group_expr: expr[0..group_expr.len()].to_vec(), | ||
| aggr_expr: expr[group_expr.len()..].to_vec(), | ||
| input: Arc::new(inputs[0].clone()), | ||
| schema: schema.clone(), | ||
| })), | ||
| }) => Ok(LogicalPlan::Aggregate(Aggregate::try_new( | ||
| Arc::new(inputs[0].clone()), | ||
| expr[0..group_expr.len()].to_vec(), | ||
| expr[group_expr.len()..].to_vec(), | ||
| schema.clone(), | ||
| )?)), | ||
| LogicalPlan::Sort(Sort { .. }) => Ok(LogicalPlan::Sort(Sort { | ||
| expr: expr.to_vec(), | ||
| input: Arc::new(inputs[0].clone()), | ||
|
|
||
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.
It's weird that this function takes either a GroupingSet expression, or an arbitrary expression. I dealt with this a lot in the subquery decorrelation - it almost feels like dynamic typing. I think the root cause might be that many of the enum values have fields inside them, rather than a struct - so it's impossible to de-reference them and pass them between functions.
How would you feel about blanket converting all enum values like
InSubquery,Exists, etc to point to structs?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 also found this frustrating to work with. Maybe we could introduce another enum?
and then
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.
Sounds good to me. This would be consistent with how we do things in the
LogicalPlan.