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 SQL planner bug when resolving columns with same name as a relation #3003

Merged
merged 6 commits into from
Aug 2, 2022

Conversation

andygrove
Copy link
Member

@andygrove andygrove commented Aug 1, 2022

Which issue does this PR close?

Closes #3002

Rationale for this change

This bug was preventing valid queries from running.

Master

❯ select * from foo;
+-----+
| foo |
+-----+
| 1   |
+-----+
1 row in set. Query took 0.011 seconds.
❯ select * from bar;
+-----+
| bar |
+-----+
| 1   |
+-----+
1 row in set. Query took 0.011 seconds.
❯ select * from foo join bar on foo.foo = bar.bar
;
Plan("The expression to get an indexed field is only valid for `List` types")

This PR

0 rows in set. Query took 0.003 seconds.
❯ select * from foo;
+-----+
| foo |
+-----+
| 1   |
+-----+
1 row in set. Query took 0.010 seconds.
❯ select * from bar;
+-----+
| bar |
+-----+
| 1   |
+-----+
1 row in set. Query took 0.011 seconds.
❯ select * from foo join bar on foo.foo = bar.bar
;
+-----+-----+
| foo | bar |
+-----+-----+
| 1   | 1   |
+-----+-----+
1 row in set. Query took 0.034 seconds.

What changes are included in this PR?

Improve logic for determining if a compound identifier is referencing a column or an indexed field

Are there any user-facing changes?

No

@andygrove andygrove added the bug Something isn't working label Aug 1, 2022
@andygrove andygrove self-assigned this Aug 1, 2022
@github-actions github-actions bot added core Core DataFusion crate sql SQL Planner labels Aug 1, 2022
@andygrove andygrove marked this pull request as ready for review August 1, 2022 16:07
@codecov-commenter
Copy link

codecov-commenter commented Aug 1, 2022

Codecov Report

Merging #3003 (475623e) into master (c7fa789) will increase coverage by 0.02%.
The diff coverage is 97.43%.

@@            Coverage Diff             @@
##           master    #3003      +/-   ##
==========================================
+ Coverage   85.81%   85.84%   +0.02%     
==========================================
  Files         282      283       +1     
  Lines       51531    51626      +95     
==========================================
+ Hits        44219    44316      +97     
+ Misses       7312     7310       -2     
Impacted Files Coverage Δ
datafusion/sql/src/planner.rs 81.91% <93.75%> (+0.03%) ⬆️
datafusion/core/tests/sql/intersection.rs 100.00% <100.00%> (ø)
datafusion/core/tests/sql/joins.rs 99.32% <100.00%> (+<0.01%) ⬆️
datafusion/core/tests/sql/mod.rs 98.26% <100.00%> (ø)
datafusion/core/tests/sql/predicates.rs 100.00% <100.00%> (ø)
datafusion/core/tests/sql/projection.rs 96.96% <100.00%> (+0.16%) ⬆️
datafusion/core/tests/sql/parquet.rs 100.00% <0.00%> (ø)
...tafusion/core/src/physical_plan/file_format/mod.rs 97.36% <0.00%> (ø)
datafusion/core/tests/sql/parquet_schema.rs 98.79% <0.00%> (ø)
... and 5 more

Help us with your feedback. Take ten seconds to tell us how you rate us.

Copy link
Contributor

@jdye64 jdye64 left a comment

Choose a reason for hiding this comment

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

LGTM, fixed the issues I was having.

@waitingkuo
Copy link
Contributor

i added a simple test case here andygrove#64

@andygrove
Copy link
Member Author

i added a simple test case here andygrove#64

Thank you @waitingkuo!

@yjshen yjshen merged commit e23925c into apache:master Aug 2, 2022
@ursabot
Copy link

ursabot commented Aug 2, 2022

Benchmark runs are scheduled for baseline = 55a1286 and contender = e23925c. e23925c 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

@waitingkuo waitingkuo mentioned this pull request Aug 2, 2022
gandronchik pushed a commit to cube-js/arrow-datafusion that referenced this pull request Sep 5, 2022
…on (apache#3003)

* repro unit test

* improve test

* fix

* make logic more robust

* add a simple test case

Co-authored-by: Wei-Ting Kuo <[email protected]>
@andygrove andygrove deleted the issue-3002 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 core Core DataFusion crate sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The expression to get an indexed field is only valid for List types (common_sub_expression_eliminate)
6 participants