Uh oh!
There was an error while loading. Please reload this page.
[SPARK-16217][SQL] Support SELECT INTO statement - #14191
Conversation
AmplabJenkins
commented
Jul 14, 2016
Can one of the admins verify this patch? |
| fromClause? | ||
| (WHERE where=booleanExpression)?) | ||
| | ((kind=SELECT setQuantifier? namedExpressionSeq fromClause? | ||
| | ((kind=SELECT setQuantifier? namedExpressionSeq (intoClause? fromClause)? |
There was a problem hiding this comment.
Hi, @wuxianxingkong .
Currently, the following seems to be not considered yet. Could you modify the syntax to support this too?
SELECT 1
INTO newtable
There was a problem hiding this comment.
Hello, @dongjoon-hyun , thank you for your advice.
SELECT1 INTO newtableThis won't work because we need oldtable info to create newtable. So the sql should be
SELECT1
INTO newtable FROM oldtableThe result from my test is: a new table called newtable was created, one column called 1 has the length of oldtable.rows.length and all elements are 1.
Did you mean there is no FROM?
There was a problem hiding this comment.
In the Spark Shell, please run the followings.
sql("select 1")
There was a problem hiding this comment.
@dongjoon-hyun
At first, I modify grammar:
But it will affect multiInsertQueryBody rule, i.e.:
FROM OLD_TABLE
INSERT INTO T1
SELECT C1
INSERT INTO T2
SELECT C2The Syntax tree before adding intoClause is:
After adding intoClause ,the tree will be:
This is because INSERT is a nonreserved keyword and matching strategy of antlr.
One of the ways I can think of is to change grammar like this:
This can solve the problem because antlr parser chooses the alternative specified first.
The grammar can support "SELECT 1 INTO newtable" now.
But this will cause confusion about querySpecification rule because of the duplication. Is there any way to make the syntax less verbose?Thanks.
dongjoon-hyun
commented
Jul 14, 2016
Hi, @wuxianxingkong . |
| // Add organization statements. | ||
| optionalMap(ctx.queryOrganization)(withQueryResultClauses). | ||
| // Add insert. | ||
| optionalMap(ctx.insertInto())(withInsertInto) |
There was a problem hiding this comment.
This allows for the following syntax:
INSERT INTO tbl_a
SELECT*
INTO tbl_a
FROM tbl_bMake sure that we cannot have both.
There was a problem hiding this comment.
We also need to check what this does with multi-insert syntax, i.e.:
FROM tbl_a
INSERT INTO tbl_b
SELECT*INSERT INTO tbl_c
SELECT*
INTO tbl_c2.Add check in multiinsertquery syntax:not allow multi insert and select into appear at the same time 3.Add check in singleinsertquery:not allow insert into and select into appear at the same time
| */ | ||
| protected def withSelectInto( | ||
| ctx: IntoClauseContext, | ||
| query: LogicalPlan): LogicalPlan = withOrigin(ctx) { |
There was a problem hiding this comment.
Why throwing a ParseException ?
gatorsmile
commented
Jun 13, 2017
@wuxianxingkong Are you still working on this? Thanks! |
gatorsmile
commented
Jun 27, 2017
We are closing it due to inactivity. please do reopen if you want to push it forward. Thanks! |
## What changes were proposed in this pull request? This PR proposes to close stale PRs, mostly the same instances with apache#18017 I believe the author in apache#14807 removed his account. Closesapache#7075Closesapache#8927Closesapache#9202Closesapache#9366Closesapache#10861Closesapache#11420Closesapache#12356Closesapache#13028Closesapache#13506Closesapache#14191Closesapache#14198Closesapache#14330Closesapache#14807Closesapache#15839Closesapache#16225Closesapache#16685Closesapache#16692Closesapache#16995Closesapache#17181Closesapache#17211Closesapache#17235Closesapache#17237Closesapache#17248Closesapache#17341Closesapache#17708Closesapache#17716Closesapache#17721Closesapache#17937 Added: Closesapache#14739Closesapache#17139Closesapache#17445Closesapache#18042Closesapache#18359 Added: Closesapache#16450Closesapache#16525Closesapache#17738 Added: Closesapache#16458Closesapache#16508Closesapache#17714 Added: Closesapache#17830Closesapache#14742 ## How was this patch tested? N/A Author: hyukjinkwon <gurwls223@gmail.com> Closesapache#18417 from HyukjinKwon/close-stale-pr.
What changes were proposed in this pull request?
This PR implements the SELECT INTO statement.
The SELECT INTO statement selects data from one table and inserts it into a new table as follows.
This statement is commonly used in SQL but not currently supported in SparkSQL.
We investigated the Catalyst and found that this statement can be implemented by improving the grammar and reusing the logical plan of CTAS.
The related JIRA is https://issues.apache.org/jira/browse/SPARK-16217
How was this patch tested?
SQLQuerySuite.