-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-19048] [SQL] Delete Partition Location when Dropping Managed Partitioned Tables in InMemoryCatalog #16448
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,6 +199,52 @@ class HiveDDLSuite | |
| assert(e.message == "Found duplicate column(s) in table definition of `tbl`: a") | ||
| } | ||
|
|
||
| test("add/drop partition with location - managed table") { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to improve the test coverage of Hive External Catalog. |
||
| val tab = "tab_with_partitions" | ||
| withTempDir { tmpDir => | ||
| val basePath = new File(tmpDir.getCanonicalPath) | ||
| val part1Path = new File(basePath + "/part1") | ||
| val part2Path = new File(basePath + "/part2") | ||
| val dirSet = part1Path :: part2Path :: Nil | ||
|
|
||
| // Before data insertion, all the directory are empty | ||
| assert(dirSet.forall(dir => dir.listFiles == null || dir.listFiles.isEmpty)) | ||
|
|
||
| withTable(tab) { | ||
| sql( | ||
| s""" | ||
| |CREATE TABLE $tab (key INT, value STRING) | ||
| |PARTITIONED BY (ds STRING, hr STRING) | ||
| """.stripMargin) | ||
| sql( | ||
| s""" | ||
| |ALTER TABLE $tab ADD | ||
| |PARTITION (ds='2008-04-08', hr=11) LOCATION '$part1Path' | ||
| |PARTITION (ds='2008-04-08', hr=12) LOCATION '$part2Path' | ||
| """.stripMargin) | ||
| assert(dirSet.forall(dir => dir.listFiles == null || dir.listFiles.isEmpty)) | ||
|
|
||
| sql(s"INSERT OVERWRITE TABLE $tab partition (ds='2008-04-08', hr=11) SELECT 1, 'a'") | ||
| sql(s"INSERT OVERWRITE TABLE $tab partition (ds='2008-04-08', hr=12) SELECT 2, 'b'") | ||
| // add partition will not delete the data | ||
| assert(dirSet.forall(dir => dir.listFiles.nonEmpty)) | ||
| checkAnswer( | ||
| spark.table(tab), | ||
| Row(1, "a", "2008-04-08", "11") :: Row(2, "b", "2008-04-08", "12") :: Nil | ||
| ) | ||
|
|
||
| sql(s"ALTER TABLE $tab DROP PARTITION (ds='2008-04-08', hr=11)") | ||
| // drop partition will delete the data | ||
| assert(part1Path.listFiles == null || part1Path.listFiles.isEmpty) | ||
| assert(part2Path.listFiles.nonEmpty) | ||
|
|
||
| sql(s"DROP TABLE $tab") | ||
| // drop table will delete the data of the managed table | ||
| assert(dirSet.forall(dir => dir.listFiles == null || dir.listFiles.isEmpty)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("add/drop partitions - external table") { | ||
| val catalog = spark.sessionState.catalog | ||
| withTempDir { tmpDir => | ||
|
|
@@ -257,9 +303,15 @@ class HiveDDLSuite | |
| // drop partition will not delete the data of external table | ||
| assert(dirSet.forall(dir => dir.listFiles.nonEmpty)) | ||
|
|
||
| sql(s"ALTER TABLE $externalTab ADD PARTITION (ds='2008-04-08', hr='12')") | ||
| sql( | ||
| s""" | ||
| |ALTER TABLE $externalTab ADD PARTITION (ds='2008-04-08', hr='12') | ||
| |PARTITION (ds='2008-04-08', hr=11) | ||
| """.stripMargin) | ||
| assert(catalog.listPartitions(TableIdentifier(externalTab)).map(_.spec).toSet == | ||
| Set(Map("ds" -> "2008-04-08", "hr" -> "12"), Map("ds" -> "2008-04-09", "hr" -> "11"))) | ||
| Set(Map("ds" -> "2008-04-08", "hr" -> "11"), | ||
| Map("ds" -> "2008-04-08", "hr" -> "12"), | ||
| Map("ds" -> "2008-04-09", "hr" -> "11"))) | ||
| // add partition will not delete the data | ||
| assert(dirSet.forall(dir => dir.listFiles.nonEmpty)) | ||
|
|
||
|
|
||
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.
We do not support
ALTER VIEW ADD PARTITION