Skip to content
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

Closed
wants to merge 55 commits into from

Conversation

gatorsmile
Copy link
Member

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 to Alter 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:

ALTER VIEW view_name RENAME TO new_view_name
  • to change the name of a view to a different name
2. ALTER VIEW SET TBLPROPERTIES

Syntax:

ALTER VIEW view_name SET TBLPROPERTIES ('comment' = new_comment);
  • to add metadata to a view
3. ALTER VIEW UNSET TBLPROPERTIES

Syntax:

ALTER VIEW view_name UNSET TBLPROPERTIES [IF EXISTS] ('comment', 'key')
  • to remove metadata from a view
4. ALTER VIEW ADD PARTITION

Syntax:

ALTER VIEW view_name ADD [IF NOT EXISTS] PARTITION spec1[, PARTITION spec2, ...]
  • to add the partitioning metadata for a view.
  • the syntax of partition spec in ALTER VIEW is identical to ALTER TABLE, EXCEPT that it is ILLEGAL to specify a LOCATION clause.
5. ALTER VIEW DROP PARTITION

Syntax:

ALTER VIEW view_name DROP [IF EXISTS] PARTITION spec1[, PARTITION spec2, ...]
  • to drop the related partition metadata for a view.

How was this patch tested?

Added the related test cases to DDLCommandSuite

gatorsmile and others added 30 commits November 13, 2015 14:50
@SparkQA
Copy link

SparkQA commented Mar 30, 2016

Test build #54528 has finished for PR 11987 at commit f379636.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@@ -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
Copy link
Contributor

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.

Copy link
Member Author

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!

Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-use label?

Copy link
Member Author

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!

Copy link
Member Author

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.

@SparkQA
Copy link

SparkQA commented Mar 31, 2016

Test build #54594 has finished for PR 11987 at commit dd34529.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Mar 31, 2016

Test build #54592 has finished for PR 11987 at commit 38ea348.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Mar 31, 2016

Test build #54598 has finished for PR 11987 at commit 48aec92.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gatorsmile
Copy link
Member Author

@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.
Copy link
Member

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 ?

Copy link
Member Author

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) {
Copy link
Contributor

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.

Copy link
Member Author

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!

@hvanhovell
Copy link
Contributor

One minor comment. LGTM pending jenkins.

@viirya
Copy link
Member

viirya commented Mar 31, 2016

LGTM

@SparkQA
Copy link

SparkQA commented Mar 31, 2016

Test build #54628 has finished for PR 11987 at commit cdb8cc0.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Mar 31, 2016

Test build #54634 has finished for PR 11987 at commit 315de90.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

# Conflicts:
#	sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
@SparkQA
Copy link

SparkQA commented Mar 31, 2016

Test build #54644 has finished for PR 11987 at commit dd1aa23.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gatorsmile
Copy link
Member Author

@andrewor14 @yhuai Could you also check if the latest version is fine? Thanks!

@andrewor14
Copy link
Contributor

LGTM merging into master, thanks @gatorsmile and reviewers!

@asfgit asfgit closed this in 446c45b Mar 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants