-
Notifications
You must be signed in to change notification settings - Fork 66
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
airframe-sql: Fix qualifier resolution #2653
Conversation
bc65bc0
to
6af22a8
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #2653 +/- ##
==========================================
+ Coverage 82.14% 82.17% +0.03%
==========================================
Files 334 334
Lines 14050 14019 -31
Branches 2213 2187 -26
==========================================
- Hits 11541 11520 -21
+ Misses 2509 2499 -10
Continue to review full report at Codecov.
|
c1 shouldBe ra1.withAlias("p1") | ||
c2 shouldBe rb1 | ||
test("ru2: resolve union with column alias") { | ||
val p = analyze("select p1 from (select id as p1 from A union all select id as p1 from B)") |
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.
The following two queries should be resolved in the same way. But the results are different:
select p1 from (select id as p1 from A union all select id as p1 from B)
-> List(p1:long := {<p1> := *id:long <- A.id, <p1> := *id:long <- B.id})
select p1 from (select id as p1 from A union all select id from B)
-> List(*p1:long <- A.id)
Also, p2
shouldn't be resolved in the following query but it's wrongly resolved.
select p2 from (select id as p1 from A union all select id as p2 from B)
-> List(*p2:long <- B.id)
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.
Thanks. Let me check
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.
Added test cases for them #2663 and working on the fix.
- Propagate qualifiers (table name) properly so that join keys can be resolved correctly. - Merge the common logic for Attribute handling (AllColumn, SingleColumn, MultiColumn, Unresolved/ResolvedAttribute) - Renamed MultiColumn -> MultiSourceColumn to clarify the meaning - TypeResolver.resolveTableScan -> Do not add qualifiers to ResolvedAttribute. Qualifiers can be added if they are given in the original SQL - Fixed Join outputAttributes: - JoinUsing(keys, ..): merge join keys as MultiSourceColumn. Added ResolveJoinUsing(...) - JoinOn(cond): Output all input child relation outputs - Changed Attribute class structure - Add common methods (e.g., qualifier, withQualifier, withAlias, etc.) - ResolvedAttribute is changed to take a single source column because we can merge multiple ResolvedAttributes with MultiSourceColumn - Removed alias parameters. Added Alias expression instead for simplicity - Moved matches, matched methods into Attribute base class - Use ColumnPath(database, table, column) pairs to properly match columns. With this change, Attributes belonging to different tables can be found as expected - UnresolvedAttribute now can take a qualifier given in the original SQL - Improved toString to distinguish different Attribute types: - SingleColumn: `(fullName):(dataType) := (expr)` - MultSourceColumn: `(fullName):(dataType) := { c1, c2, ...}` - Alias: `<fullName> := (expr)` - ResolvedAttribute `*(fullName):(dataType) <- (sourceColumn)` - Simplified Set operation's `outputAttributes` method by using transpose and the newly added Attribute methods - TypeResolver - Fixed join, sort, and projection column resolvers to use new Attribute - Extracted attribute match and merge logic to Attribute class methods. - When resolving attributes, if there is a source column without any change, propagate it to the resolved attribute - Optimize nested SingleColumn(ResolvedAttribute, ...) as a single ResolvedAttribute - Reorder resolver rules. GroupBy, SortBy need to be processed last after resolving select items - SQLGenerator - Changed the behavior within SELECT ... and other part (e.g., GROUP BY ...). In generating select items, printSelectItem will be used first to avoid using alias (e.g., c as a1) in ORDER BY, GROUP BY clauses. Reformat
Purpose
Major changes
(fullName):(dataType) := (expr)
(fullName):(dataType) := { c1, c2, ...}
<fullName> := (expr)
*(fullName):(dataType) <- (sourceColumn)
outputAttributes
method by using transpose and the newly added Attribute methodsTypeResolver changes
Minor changes