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

Fix invalid projection in CommonSubexprEliminate #2915

Merged
merged 3 commits into from
Jul 15, 2022

Conversation

andygrove
Copy link
Member

@andygrove andygrove commented Jul 14, 2022

Which issue does this PR close?

Closes #2907

Rationale for this change

CommonSubexprEliminate created invalid projections when processing joins where there were one or more columns with the same unqualified name on each side of the join (as happens when you join to the same table multiple times).

What changes are included in this PR?

  • Add a unit test to demonstrate the bug
  • Use qualified name instead of unqualified name in the HashSet that tracks which fields have already been added to the projection
  • Remove the code that tried to merge in the input schema since this is not required

Are there any user-facing changes?

No

@github-actions github-actions bot added the optimizer Optimizer rules label Jul 14, 2022
@andygrove
Copy link
Member Author

@jdye64 Here is the fix for the root cause of the invalid projections in the optimizer

@andygrove
Copy link
Member Author

@waynexia fyi

@andygrove andygrove added the bug Something isn't working label Jul 14, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #2915 (d9f18fa) into master (8ad3df5) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2915   +/-   ##
=======================================
  Coverage   85.30%   85.31%           
=======================================
  Files         274      274           
  Lines       49267    49279   +12     
=======================================
+ Hits        42028    42040   +12     
  Misses       7239     7239           
Impacted Files Coverage Δ
...tafusion/optimizer/src/common_subexpr_eliminate.rs 94.30% <100.00%> (+0.18%) ⬆️
datafusion/expr/src/window_frame.rs 92.43% <0.00%> (-0.85%) ⬇️
datafusion/expr/src/logical_plan/plan.rs 77.14% <0.00%> (ø)
datafusion/physical-expr/src/expressions/binary.rs 95.12% <0.00%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8ad3df5...d9f18fa. Read the comment docs.

Copy link
Member

@waynexia waynexia left a comment

Choose a reason for hiding this comment

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

Thanks for pinning this down ❤️ This patch looks good to me.

@@ -282,15 +282,13 @@ fn build_project_plan(
}

for field in input.schema().fields() {
if !fields_set.contains(field.name()) {
fields_set.insert(field.name().to_owned());
if fields_set.insert(field.qualified_name()) {
Copy link
Member

Choose a reason for hiding this comment

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

Nice simplification

Use qualified name instead of unqualified name in the HashSet that tracks which fields have already been added to the projection

This is correct 👍 It used to be inconsistent with L287 which uses qualified name.

fields.push(field.clone());
project_exprs.push(Expr::Column(field.qualified_column()));
}
}

let mut schema = DFSchema::new_with_metadata(fields, HashMap::new())?;
schema.merge(input.schema());
Copy link
Member

Choose a reason for hiding this comment

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

merge is done in the previous for loop so I think this is redundant. Let's remove it.

@alamb alamb merged commit b5537e7 into apache:master Jul 15, 2022
@ursabot
Copy link

ursabot commented Jul 15, 2022

Benchmark runs are scheduled for baseline = d8a2f58 and contender = b5537e7. b5537e7 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

@andygrove andygrove deleted the fix-incorrect-projection branch January 27, 2023 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working optimizer Optimizer rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimization rule CommonSubexprEliminate creates invalid projections
5 participants