-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-27444][SQL] multi-select can be used in subquery #24348
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,8 +81,7 @@ singleTableSchema | |
|
|
||
| statement | ||
| : query #statementDefault | ||
| | insertStatement #insertStatementDefault | ||
| | multiSelectStatement #multiSelectStatementDefault | ||
| | ctes? dmlStatementNoWith #dmlStatement | ||
| | USE db=identifier #use | ||
| | CREATE database (IF NOT EXISTS)? identifier | ||
| (COMMENT comment=STRING)? locationSpec? | ||
|
|
@@ -356,14 +355,14 @@ resource | |
| : identifier STRING | ||
| ; | ||
|
|
||
| insertStatement | ||
| : (ctes)? insertInto queryTerm queryOrganization #singleInsertQuery | ||
| | (ctes)? fromClause multiInsertQueryBody+ #multiInsertQuery | ||
| dmlStatementNoWith | ||
| : insertInto queryTerm queryOrganization #singleInsertQuery | ||
| | fromClause multiInsertQueryBody+ #multiInsertQuery | ||
| ; | ||
|
|
||
| queryNoWith | ||
| : queryTerm queryOrganization #noWithQuery | ||
| | fromClause selectStatement #queryWithFrom | ||
| | fromClause selectStatement+ #queryWithFrom | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should we name the label
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, multi-select is still one query :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cloud-fan Okay.. sounds good to me. |
||
| ; | ||
|
|
||
| queryOrganization | ||
|
|
@@ -379,10 +378,6 @@ multiInsertQueryBody | |
| : insertInto selectStatement | ||
| ; | ||
|
|
||
| multiSelectStatement | ||
| : (ctes)? fromClause selectStatement+ #multiSelect | ||
| ; | ||
|
|
||
| selectStatement | ||
| : querySpecification queryOrganization | ||
| ; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,15 +132,19 @@ class PlanParserSuite extends AnalysisTest { | |
| table("a").select(star()).union(table("a").where('s < 10).select(star()))) | ||
| intercept( | ||
| "from a select * select * from x where a.s < 10", | ||
| "Multi-select queries cannot have a FROM clause in their individual SELECT statements") | ||
| "This select statement can not have FROM cause as its already specified upfront") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you know what? cannot is correct too and more usual :-).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is copied from the old error message: https://github.com/apache/spark/pull/24348/files#diff-9847f5cef7cf7fbc5830fbc6b779ee10L133 We can update this
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's fine. I didn't mean we should fix now. just wanted to say it :-). |
||
| intercept( | ||
| "from a select * from b", | ||
| "Individual select statement can not have FROM cause as its already specified in " + | ||
| "the outer query block") | ||
| "This select statement can not have FROM cause as its already specified upfront") | ||
| assertEqual( | ||
| "from a insert into tbl1 select * insert into tbl2 select * where s < 10", | ||
| table("a").select(star()).insertInto("tbl1").union( | ||
| table("a").where('s < 10).select(star()).insertInto("tbl2"))) | ||
| assertEqual( | ||
| "select * from (from a select * select *)", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for adding this. |
||
| table("a").select(star()) | ||
| .union(table("a").select(star())) | ||
| .as("__auto_generated_subquery_name").select(star())) | ||
| } | ||
|
|
||
| test("query organization") { | ||
|
|
||
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.
move the
ctes?to the parent entry, to save duplicated code. This is a simplification of #24150