Skip to content
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

Build aggregate schema in Aggregate::try_new #3739

Merged
merged 8 commits into from Oct 6, 2022

Conversation

andygrove
Copy link
Member

Which issue does this PR close?

Closes #3738

Rationale for this change

We had duplicate code for building an aggregate schema. This code is now inside Aggregate::try_new so we don't have to duplicate it everwhere,

What changes are included in this PR?

Refactoring to eliminate duplicate code for building aggregate schema

Are there any user-facing changes?

Comment on lines -704 to -711
let grouping_expr: Vec<Expr> = grouping_set_to_exprlist(group_expr.as_slice())?;

let all_expr = grouping_expr.iter().chain(aggr_expr.iter());
validate_unique_names("Aggregations", all_expr.clone())?;
let aggr_schema = DFSchema::new_with_metadata(
exprlist_to_fields(all_expr, &self.plan)?,
self.plan.schema().metadata().clone(),
)?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is moved into Aggregate::try_new

Comment on lines +1345 to +1351
let grouping_expr: Vec<Expr> = grouping_set_to_exprlist(group_expr.as_slice())?;
let all_expr = grouping_expr.iter().chain(aggr_expr.iter());
validate_unique_names("Aggregations", all_expr.clone())?;
let schema = DFSchema::new_with_metadata(
exprlist_to_fields(all_expr, &input)?,
input.schema().metadata().clone(),
)?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the code moved from LogicalPlanBuilder::aggregate

Comment on lines -335 to -343
let new_schema = DFSchema::new_with_metadata(
schema
.fields()
.iter()
.filter(|x| new_required_columns.contains(&x.qualified_column()))
.cloned()
.collect(),
schema.metadata().clone(),
)?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was problematic and is now replaced with the code used elsewhere

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I agree having the caller have to specify (correctly) the aggregate schema is a recipe for disaster

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love it

Comment on lines -335 to -343
let new_schema = DFSchema::new_with_metadata(
schema
.fields()
.iter()
.filter(|x| new_required_columns.contains(&x.qualified_column()))
.cloned()
.collect(),
schema.metadata().clone(),
)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I agree having the caller have to specify (correctly) the aggregate schema is a recipe for disaster

datafusion/expr/src/logical_plan/plan.rs Show resolved Hide resolved
@alamb
Copy link
Contributor

alamb commented Oct 6, 2022

CI failure appears unrelated: #3743

@andygrove andygrove merged commit 38cf2eb into apache:master Oct 6, 2022
@andygrove andygrove deleted the aggregate-schema branch October 6, 2022 20:46
@ursabot
Copy link

ursabot commented Oct 6, 2022

Benchmark runs are scheduled for baseline = 8dcef91 and contender = 38cf2eb. 38cf2eb is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

projection_push_down produces invalid aggregate plans in some cases
3 participants