Skip to content

Fix SQL planner bug when resolving columns with same name as a relation - #3003

Merged
yjshen merged 6 commits into
apache:masterfrom
andygrove:issue-3002
Aug 2, 2022
Merged

Fix SQL planner bug when resolving columns with same name as a relation#3003
yjshen merged 6 commits into
apache:masterfrom
andygrove:issue-3002

Conversation

@andygrove

@andygroveandygrove commented Aug 1, 2022

Copy link
Copy Markdown
Member

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

@andygroveandygrove added the bug Something isn't working label Aug 1, 2022
@andygroveandygrove self-assigned this Aug 1, 2022
@github-actionsgithub-actionsBot 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

codecov-commenter commented Aug 1, 2022

Copy link
Copy Markdown

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 FilesCoverage Δ
datafusion/sql/src/planner.rs81.91% <93.75%> (+0.03%)⬆️
datafusion/core/tests/sql/intersection.rs100.00% <100.00%> (ø)
datafusion/core/tests/sql/joins.rs99.32% <100.00%> (+<0.01%)⬆️
datafusion/core/tests/sql/mod.rs98.26% <100.00%> (ø)
datafusion/core/tests/sql/predicates.rs100.00% <100.00%> (ø)
datafusion/core/tests/sql/projection.rs96.96% <100.00%> (+0.16%)⬆️
datafusion/core/tests/sql/parquet.rs100.00% <0.00%> (ø)
...tafusion/core/src/physical_plan/file_format/mod.rs97.36% <0.00%> (ø)
datafusion/core/tests/sql/parquet_schema.rs98.79% <0.00%> (ø)
... and 5 more

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

@jdye64jdye64 left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

i added a simple test case here andygrove#64

@andygrove

Copy link
Copy Markdown
MemberAuthor

i added a simple test case here andygrove#64

Thank you @waitingkuo!

@yjshen
yjshen merged commit e23925c into apache:masterAug 2, 2022
@ursabot

Copy link
Copy Markdown

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

@waitingkuowaitingkuo 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 <waitingkuo0527@gmail.com>
@andygrove
andygrove deleted the issue-3002 branch January 27, 2023 18:56
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't workingcoreCore DataFusion cratesqlSQL 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

@andygrove@codecov-commenter@waitingkuo@ursabot@yjshen@jdye64