-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-14125] [SQL] Native DDL Support: Alter View #12324
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
Closed
Closed
Changes from 59 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
01e4cdf
Merge remote-tracking branch 'upstream/master'
gatorsmile 6835704
Merge remote-tracking branch 'upstream/master'
gatorsmile 9180687
Merge remote-tracking branch 'upstream/master'
gatorsmile b38a21e
SPARK-11633
gatorsmile d2b84af
Merge remote-tracking branch 'upstream/master' into joinMakeCopy
gatorsmile fda8025
Merge remote-tracking branch 'upstream/master'
gatorspark ac0dccd
Merge branch 'master' of https://github.com/gatorsmile/spark
gatorspark 6e0018b
Merge remote-tracking branch 'upstream/master'
0546772
converge
gatorsmile b37a64f
converge
gatorsmile c2a872c
Merge remote-tracking branch 'upstream/master'
gatorsmile ab6dbd7
Merge remote-tracking branch 'upstream/master'
gatorsmile 4276356
Merge remote-tracking branch 'upstream/master'
gatorsmile 2dab708
Merge remote-tracking branch 'upstream/master'
gatorsmile 0458770
Merge remote-tracking branch 'upstream/master'
gatorsmile 1debdfa
Merge remote-tracking branch 'upstream/master'
gatorsmile 763706d
Merge remote-tracking branch 'upstream/master'
gatorsmile 4de6ec1
Merge remote-tracking branch 'upstream/master'
gatorsmile 9422a4f
Merge remote-tracking branch 'upstream/master'
gatorsmile 52bdf48
Merge remote-tracking branch 'upstream/master'
gatorsmile 1e95df3
Merge remote-tracking branch 'upstream/master'
gatorsmile fab24cf
Merge remote-tracking branch 'upstream/master'
gatorsmile 8b2e33b
Merge remote-tracking branch 'upstream/master'
gatorsmile 2ee1876
Merge remote-tracking branch 'upstream/master'
gatorsmile b9f0090
Merge remote-tracking branch 'upstream/master'
gatorsmile ade6f7e
Merge remote-tracking branch 'upstream/master'
gatorsmile 9fd63d2
Merge remote-tracking branch 'upstream/master'
gatorsmile 5199d49
Merge remote-tracking branch 'upstream/master'
gatorsmile 404214c
Merge remote-tracking branch 'upstream/master'
gatorsmile c001dd9
Merge remote-tracking branch 'upstream/master'
gatorsmile 59daa48
Merge remote-tracking branch 'upstream/master'
gatorsmile 41d5f64
Merge remote-tracking branch 'upstream/master'
gatorsmile 472a6e3
Merge remote-tracking branch 'upstream/master'
gatorsmile 0fba10a
Merge remote-tracking branch 'upstream/master'
gatorsmile cbf73b3
Merge remote-tracking branch 'upstream/master'
gatorsmile c08f561
Merge remote-tracking branch 'upstream/master'
gatorsmile 474df88
Merge remote-tracking branch 'upstream/master'
gatorsmile 3d9828d
Merge remote-tracking branch 'upstream/master'
gatorsmile 72d2361
Merge remote-tracking branch 'upstream/master'
gatorsmile 07afea5
Merge remote-tracking branch 'upstream/master'
gatorsmile 8bf2007
Merge remote-tracking branch 'upstream/master'
gatorsmile 87a165b
Merge remote-tracking branch 'upstream/master'
gatorsmile b9359cd
Merge remote-tracking branch 'upstream/master'
gatorsmile 65bd090
Merge remote-tracking branch 'upstream/master'
gatorsmile babf2da
Merge remote-tracking branch 'upstream/master'
gatorsmile 9e09469
Merge remote-tracking branch 'upstream/master'
gatorsmile 50a8e4a
Merge remote-tracking branch 'upstream/master'
gatorsmile 34e44da
fix 1
gatorsmile c040e1d
Merge remote-tracking branch 'upstream/master' into alterView
gatorsmile c8811bc
correct compilation errors
gatorsmile f3337fa
Merge remote-tracking branch 'upstream/master'
gatorsmile 66cb2c1
Merge remote-tracking branch 'upstream/master' into alterView
gatorsmile c55ab12
impl
gatorsmile 09cc36d
Merge remote-tracking branch 'upstream/master'
gatorsmile ed5a7d0
added more test cases.
gatorsmile cd20636
Merge remote-tracking branch 'upstream/master' into alterView
gatorsmile 83a1915
Merge remote-tracking branch 'upstream/master'
gatorsmile fdc653f
Merge branch 'alterView' into alterViewNew
gatorsmile e82aa47
address comments.
gatorsmile db7f931
address comments.
gatorsmile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,6 +131,124 @@ class HiveDDLSuite extends QueryTest with SQLTestUtils with TestHiveSingleton { | |
| } | ||
| } | ||
|
|
||
| test("alter views - rename") { | ||
| val tabName = "tab1" | ||
| withTable(tabName) { | ||
| sqlContext.range(10).write.saveAsTable(tabName) | ||
| val oldViewName = "view1" | ||
| val newViewName = "view2" | ||
| withView(oldViewName, newViewName) { | ||
| val catalog = hiveContext.sessionState.catalog | ||
| sql(s"CREATE VIEW $oldViewName AS SELECT * FROM $tabName") | ||
|
|
||
| assert(catalog.tableExists(TableIdentifier(oldViewName))) | ||
| assert(!catalog.tableExists(TableIdentifier(newViewName))) | ||
| sql(s"ALTER VIEW $oldViewName RENAME TO $newViewName") | ||
| assert(!catalog.tableExists(TableIdentifier(oldViewName))) | ||
| assert(catalog.tableExists(TableIdentifier(newViewName))) | ||
|
|
||
| sql(s"DROP VIEW $newViewName") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("alter views - set/unset tblproperties") { | ||
| val tabName = "tab1" | ||
| withTable(tabName) { | ||
| sqlContext.range(10).write.saveAsTable(tabName) | ||
| val viewName = "view1" | ||
| withView(viewName) { | ||
| val catalog = hiveContext.sessionState.catalog | ||
| sql(s"CREATE VIEW $viewName AS SELECT * FROM $tabName") | ||
|
|
||
| assert(catalog.getTableMetadata(TableIdentifier(viewName)) | ||
| .properties.filter(_._1 != "transient_lastDdlTime") == Map()) | ||
| sql(s"ALTER VIEW $viewName SET TBLPROPERTIES ('p' = 'an')") | ||
| assert(catalog.getTableMetadata(TableIdentifier(viewName)) | ||
| .properties.filter(_._1 != "transient_lastDdlTime") == Map("p" -> "an")) | ||
|
|
||
| // no exception or message will be issued if we set it again | ||
| sql(s"ALTER VIEW $viewName SET TBLPROPERTIES ('p' = 'an')") | ||
| assert(catalog.getTableMetadata(TableIdentifier(viewName)) | ||
| .properties.filter(_._1 != "transient_lastDdlTime") == Map("p" -> "an")) | ||
|
|
||
| // the value will be updated if we set the same key to a different value | ||
| sql(s"ALTER VIEW $viewName SET TBLPROPERTIES ('p' = 'b')") | ||
| assert(catalog.getTableMetadata(TableIdentifier(viewName)) | ||
| .properties.filter(_._1 != "transient_lastDdlTime") == Map("p" -> "b")) | ||
|
|
||
| sql(s"ALTER VIEW $viewName UNSET TBLPROPERTIES ('p')") | ||
| assert(catalog.getTableMetadata(TableIdentifier(viewName)) | ||
| .properties.filter(_._1 != "transient_lastDdlTime") == Map()) | ||
|
|
||
| val message = intercept[AnalysisException] { | ||
| sql(s"ALTER VIEW $viewName UNSET TBLPROPERTIES ('p')") | ||
| }.getMessage | ||
| assert(message.contains( | ||
| "attempted to unset non-existent property 'p' in table '`view1`'")) | ||
|
|
||
| sql(s"DROP VIEW $viewName") | ||
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| test("alter views and alter table - misuse") { | ||
| val tabName = "tab1" | ||
| withTable(tabName) { | ||
| sqlContext.range(10).write.saveAsTable(tabName) | ||
| val oldViewName = "view1" | ||
| val newViewName = "view2" | ||
| withView(oldViewName, newViewName) { | ||
| val catalog = hiveContext.sessionState.catalog | ||
| sql(s"CREATE VIEW $oldViewName AS SELECT * FROM $tabName") | ||
|
|
||
| assert(catalog.tableExists(TableIdentifier(tabName))) | ||
| assert(catalog.tableExists(TableIdentifier(oldViewName))) | ||
|
|
||
| var message = intercept[AnalysisException] { | ||
| sql(s"ALTER VIEW $tabName RENAME TO $newViewName") | ||
| }.getMessage | ||
| assert(message.contains( | ||
| "Cannot alter a table with ALTER VIEW. Please use ALTER TABLE instead")) | ||
|
|
||
| message = intercept[AnalysisException] { | ||
| sql(s"ALTER VIEW $tabName SET TBLPROPERTIES ('p' = 'an')") | ||
| }.getMessage | ||
| assert(message.contains( | ||
| "Cannot alter a table with ALTER VIEW. Please use ALTER TABLE instead")) | ||
|
|
||
| message = intercept[AnalysisException] { | ||
| sql(s"ALTER VIEW $tabName UNSET TBLPROPERTIES ('p')") | ||
| }.getMessage | ||
| assert(message.contains( | ||
| "Cannot alter a table with ALTER VIEW. Please use ALTER TABLE instead")) | ||
|
|
||
| message = intercept[AnalysisException] { | ||
| sql(s"ALTER TABLE $oldViewName RENAME TO $newViewName") | ||
| }.getMessage | ||
| assert(message.contains( | ||
| "Cannot alter a view with ALTER TABLE. Please use ALTER VIEW instead")) | ||
|
|
||
| message = intercept[AnalysisException] { | ||
| sql(s"ALTER TABLE $oldViewName SET TBLPROPERTIES ('p' = 'an')") | ||
| }.getMessage | ||
| assert(message.contains( | ||
| "Cannot alter a view with ALTER TABLE. Please use ALTER VIEW instead")) | ||
|
|
||
| message = intercept[AnalysisException] { | ||
| sql(s"ALTER TABLE $oldViewName UNSET TBLPROPERTIES ('p')") | ||
| }.getMessage | ||
| assert(message.contains( | ||
| "Cannot alter a view with ALTER TABLE. Please use ALTER VIEW instead")) | ||
|
|
||
| assert(catalog.tableExists(TableIdentifier(tabName))) | ||
| assert(catalog.tableExists(TableIdentifier(oldViewName))) | ||
|
|
||
| sql(s"DROP VIEW $newViewName") | ||
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| test("drop table using drop view") { | ||
| withTable("tab1") { | ||
| sql("CREATE TABLE tab1(c1 int)") | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
withViewwill help us drop the view at last.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, remove it now. Thanks!