-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-20962][SQL] Support subquery column aliases in FROM clause #18185
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
Conversation
|
Test build #77671 has started for PR 18185 at commit |
|
Jenkins, retest this please. |
|
Test build #77672 has finished for PR 18185 at commit
|
|
Test build #79519 has finished for PR 18185 at commit
|
|
@gatorsmile If you get time, could you check this? Thanks! |
|
ping |
|
Will review it tonight. Thanks! |
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.
We need a DDL syntax example here. Could you add it?
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.
ok
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 impact of changing SubqueryAlias is too big. How about adding a new operator node UnresolvedColumnAlias? In the analyzer, UnresolvedColumnAlias will be replaced by a Project? The resolution is by position.
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.
ok, I'll check if we could do so.
|
Test build #79901 has finished for PR 18185 at commit
|
|
@gatorsmile ok, done. Could you check again? |
|
ping |
| } | ||
| val subquery = SubqueryAlias(alias, plan(ctx.queryNoWith).optionalMap(ctx.sample)(withSample)) | ||
| if (ctx.tableAlias.identifierList != null) { | ||
| val columnNames = visitIdentifierList(ctx.tableAlias.identifierList) |
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.
Nit: columnNames -> columnAliases
| * | ||
| * @param outputColumnNames the column names for this subquery. | ||
| * @param child the logical plan of this subquery. | ||
| */ |
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.
Nit: UnresolvedSubqueryColumnAlias -> UnresolvedSubqueryColumnAliases
| * SELECT col1, col2 FROM testData AS t(col1, col2); | ||
| * }}} | ||
| * | ||
| * @param outputColumnNames the column names for this subquery. |
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.
Nit: the logical plan of this subquery -> the [[LogicalPlan]] on which this subquery column aliases apply
| override lazy val resolved = false | ||
| } | ||
|
|
||
| /** |
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.
resolved by positions.
| // Checks if the number of the aliases equals to the number of output columns | ||
| // in the subquery. | ||
| if (columnNames.size != outputAttrs.size) { | ||
| u.failAnalysis(s"Number of column aliases does not match number of columns. " + |
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.
Nit: remove the string Interpolator s.
|
LGTM except a few minor comments. Thanks for working on it! |
|
Thanks! Fixed. |
|
Test build #80010 has finished for PR 18185 at commit
|
|
Test build #80011 has finished for PR 18185 at commit
|
|
@gatorsmile ok |
| // rule: ResolveDeserializer. | ||
| case plan if containsDeserializer(plan.expressions) => plan | ||
|
|
||
| case u @ UnresolvedSubqueryColumnAliases(columnNames, child) if child.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.
The last question. What is the reason why we do not have a separate analyzer rule?
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.
Yea, I forgot to move this rule outside. I'll update soon.
|
Test build #80031 has finished for PR 18185 at commit
|
|
LGTM. Thanks! Merging to master. |
… visitTableName ## What changes were proposed in this pull request? This pr (follow-up of #18772) used `UnresolvedSubqueryColumnAliases` for `visitTableName` in `AstBuilder`, which is a new unresolved `LogicalPlan` implemented in #18185. ## How was this patch tested? Existing tests Author: Takeshi Yamamuro <[email protected]> Closes #18857 from maropu/SPARK-20963-FOLLOWUP.
What changes were proposed in this pull request?
This pr added parsing rules to support subquery column aliases in FROM clause.
This pr is a sub-task of #18079.
How was this patch tested?
Added tests in
PlanParserSuiteandSQLQueryTestSuite.