-
Notifications
You must be signed in to change notification settings - Fork 67
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
sql (fix): Resolve UNNEST earlier to prevent cyclic references #3312
Conversation
c6abedf
to
52528d3
Compare
52528d3
to
359a608
Compare
I also don't have a clear idea of how we should represent Unnest. Need to check how UNNEST is handled in Trino or SparkSQL. |
|
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #3312 +/- ##
==========================================
- Coverage 82.71% 82.60% -0.11%
==========================================
Files 355 355
Lines 14836 14861 +25
Branches 2510 2537 +27
==========================================
+ Hits 12271 12276 +5
- Misses 2565 2585 +20
... and 4 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
case SingleColumn(a: Attribute, qualifier, tableAlias, _) if a.resolved => | ||
a.withQualifier(qualifier).withTableAlias(tableAlias) |
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 case cannot be resolved without this fix:
select t.id from (select id from A) as t(id)
} | ||
|
||
private def resolveUnnest(u: Unnest, j: Join, context: AnalyzerContext): Unnest = { | ||
val resolvedAttributes = j.outputAttributes.filter(_.resolved) |
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.
Excluding unresolved attributes is a workaround to prevent cyclic references easily.
Ok. Thanks for the explanation. I understand the fix |
Case 1
This SQL is valid but fails to resolve with the following error:
Because the output attribute of AliasedRelation (
t (name)
) is included in the source attributes when resolveUNNEST (name)
here:airframe/airframe-sql/src/main/scala/wvlet/airframe/sql/analyzer/TypeResolver.scala
Lines 319 to 321 in 49d31ba
r
is CrossJoinr.inputAttributes
isleft.outputAttributes + right.outputAttributes
right
is AliasedRelation(Unnest)I think output attributes of AliasedRelation shouldn't be in the scope when Unnest is resolved but I didn't come up with an easy fix for this issue.
Case 2
This SQL is also valid but fails to resolve with the following error:
Maybe this is because the resolved UNNEST column has a qualifier. This case might not be UNNEST specific.