dilipbiswal opened a new 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
 
 
   ## What changes were proposed in this pull request?
   Currently in the grammar file the rule `query` is responsible to parse both 
select and insert statements. As a result, we need to have more semantic checks 
in the code to guard against in valid insert constructs in a query. Couple of 
examples are in the `visitCreateView` and `visitAlterView` functions. One other 
issue is that, we don't catch the `invalid insert constructs` in all the 
places. Here are couple of examples :
   
   ```SQL
   select * from (insert into bar values (2));
   ```
   ```
   Error in query: unresolved operator 'Project [*];
   'Project [*]
   +- SubqueryAlias `__auto_generated_subquery_name`
      +- InsertIntoHiveTable `default`.`bar`, 
org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, false, false, [c1]
         +- Project [cast(col1#18 as int) AS c1#20]
            +- LocalRelation [col1#18]
   ```
   
   ```SQL
   select * from foo where c1 in (insert into bar values (2))
   ```
   ```
   Error in query: cannot resolve '(default.foo.`c1` IN (listquery()))' due to 
data type mismatch: 
   The number of columns in the left hand side of an IN subquery does not match 
the
   number of columns in the output of subquery.
   #columns in left hand side: 1.
   #columns in right hand side: 0.
   
   Left side columns:
   [default.foo.`c1`].
   Right side columns:
   [].;;
   'Project [*]
   +- 'Filter c1#6 IN (list#5 [])
      :  +- InsertIntoHiveTable `default`.`bar`, 
org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, false, false, [c1]
      :     +- Project [cast(col1#7 as int) AS c1#9]
      :        +- LocalRelation [col1#7]
      +- SubqueryAlias `default`.`foo`
         +- HiveTableRelation `default`.`foo`, 
org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, [c1#6]
   ```
   
   For both the cases above, we should reject the syntax at parser level.
   
   In this PR, we create two top-level parser rules to parse `SELECT` and 
`INSERT` respectively.
   ## How was this patch tested?
   Added tests to PlanParserSuite and removed the semantic check tests from 
SparkSqlParserSuites.

----------------------------------------------------------------
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]

Reply via email to