dilipbiswal commented on a change in pull request #24150: [SPARK-27209][SQL]
Split parsing of SELECT and INSERT into two top-level rules in the grammar file.
URL: https://github.com/apache/spark/pull/24150#discussion_r267994405
##########
File path:
sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
##########
@@ -354,9 +355,14 @@ resource
: identifier STRING
;
+insertStatement
+ : (ctes)? insertInto queryTerm queryOrganization
#singleInsertQuery
+ | (ctes)? fromClause multiInsertQueryBody+
#multiInsertQuery
+ ;
+
queryNoWith
- : insertInto? queryTerm queryOrganization
#singleInsertQuery
- | fromClause multiInsertQueryBody+
#multiInsertQuery
+ : queryTerm queryOrganization
#noWithQuery
+ | fromClause querySpecification queryOrganization
#queryWithFrom
Review comment:
@cloud-fan Actually this is sort of tricky.. I initially didn't have this
rule thinking insertStatement should take care of this. But it didn't .
```
FROM (FROM TEST SELECT TRANSFORM(KEY, VALUE) USING 'CAT' AS (`THING1` INT,
THING2 STRING)) T SELECT THING1 + 1
```
In this case, we have nested from clause. and the inner from is handled by
rule `aliasedQuery`. If we see the definition, it calls `queryNoWith` and we
resolve the nested FROM with along with querySpecification(the transform query)
by using queryNoWith:queryWithFrom rule.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]