-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
[SPARK-14182] [SQL] Parse DDL Command: Alter View #11987
Conversation
# Conflicts: # sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala
Test build #54528 has finished for PR 11987 at commit
|
@@ -102,6 +102,15 @@ statement | |||
(PARTITIONED ON identifierList)? | |||
(TBLPROPERTIES tablePropertyList)? AS query #createView | |||
| ALTER VIEW tableIdentifier AS? query #alterViewQuery | |||
| ALTER VIEW from=tableIdentifier AS? RENAME TO to=tableIdentifier #renameView |
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.
I don't think we need a dedicated label (i.e. #renameView
) for this, we can just re-use #renameTable
for this. That way you don't have to add any code to SparkSqlParser
. The same goes for all these commands.
We can also integrate this with the ALTER TABLE ...
equivalent rules (i.e. ALTER (TABLE|VIEW) ...
. But this is a bit messier, and I'll leave that to you.
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.
Fine, I will combine them for renameView
, setViewProperties
, unsetViewProperties
.
I still want to keep addViewPartition
and dropViewPartitions
. These two have different syntax. Different from Alter Table, addViewPartition
is unable to accept the location
clauses; dropViewPartitions
is unable to accept PURGE
.
I am wondering if that makes sense? 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.
It does. You can keep the grammar for addViewPartition
and dropViewPartitions
, but reuse the labels. The parser will then catch unallowed syntax, and we will not duplicate code.
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.
Great! Will do the change. Thanks!
@@ -74,12 +75,16 @@ statement | |||
SET SKEWED LOCATION skewedLocationList #setTableSkewLocations | |||
| ALTER TABLE tableIdentifier ADD (IF NOT EXISTS)? | |||
partitionSpecLocation+ #addTablePartition | |||
| ALTER VIEW tableIdentifier ADD (IF NOT EXISTS)? | |||
partitionSpec+ #addViewPartition |
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.
re-use label?
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.
@hvanhovell Still trying to combine addViewPartition
and addTablePartition
. Will keep you posted. 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.
@viirya Yeah, I am doing it now.
Test build #54594 has finished for PR 11987 at commit
|
Test build #54592 has finished for PR 11987 at commit
|
Test build #54598 has finished for PR 11987 at commit
|
@andrewor14 @rxin Based on your comments, the latest commits removed all the changes on the ANTLR3 codes, which will be removed soon. Now, the only changes in this PR are against ANTLR4. @hvanhovell @viirya Please check if the changes on Parser is clean and clear. Thank you! : ) |
* Add Partition in ALTER TABLE/VIEW: add the table/view partitions. | ||
* 'partitionSpecsAndLocs': the syntax of ALTER VIEW is identical to ALTER TABLE, | ||
* EXCEPT that it is ILLEGAL to specify a LOCATION clause. | ||
* An error message will be issued if the partition exists, unless 'ifNotExists' is 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.
unless 'ifNotExists' is false. -> unless 'ifNotExists' is true ?
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.
Thanks, fixed.
val spec = visitNonOptionalPartitionSpec(splCtx.partitionSpec) | ||
val location = Option(splCtx.locationSpec).map(visitLocationSpec) | ||
spec -> location | ||
val specsAndLocs = if (ctx.partitionSpecLocation.isEmpty) { |
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.
Minor: I slightly prefer checking if partitionSpec
is non empty. This is effectively the same, since they are mutally exclusive.
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.
Sure, I can make a quick change. Thanks!
One minor comment. LGTM pending jenkins. |
LGTM |
Test build #54628 has finished for PR 11987 at commit
|
Test build #54634 has finished for PR 11987 at commit
|
# Conflicts: # sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
Test build #54644 has finished for PR 11987 at commit
|
@andrewor14 @yhuai Could you also check if the latest version is fine? Thanks! |
LGTM merging into master, thanks @gatorsmile and reviewers! |
What changes were proposed in this pull request?
This PR is to provide native parsing support for DDL commands:
Alter View
. Since its AST trees are highly similar toAlter Table
. Thus, both implementation are integrated into the same one.Based on the Hive DDL document:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL and https://cwiki.apache.org/confluence/display/Hive/PartitionedViews
1. ALTER VIEW RENAME
Syntax:
2. ALTER VIEW SET TBLPROPERTIES
Syntax:
3. ALTER VIEW UNSET TBLPROPERTIES
Syntax:
4. ALTER VIEW ADD PARTITION
Syntax:
ALTER VIEW
is identical toALTER TABLE
, EXCEPT that it is ILLEGAL to specify aLOCATION
clause.5. ALTER VIEW DROP PARTITION
Syntax:
How was this patch tested?
Added the related test cases to
DDLCommandSuite