Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/15704#discussion_r87555750
--- Diff:
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
---
@@ -225,6 +226,102 @@ class HiveDDLSuite
}
}
+ test("SPARK-17732: Drop partitions by filter") {
+ withTable("sales") {
+ sql("CREATE TABLE sales(id INT) PARTITIONED BY (country STRING,
quarter STRING)")
+
+ for (country <- Seq("US", "CA", "KR")) {
+ for (quarter <- 1 to 4) {
+ sql(s"ALTER TABLE sales ADD PARTITION (country='$country',
quarter='$quarter')")
+ }
+ }
+
+ sql("ALTER TABLE sales DROP PARTITION (country < 'KR', quarter >
'2')")
+ checkAnswer(sql("SHOW PARTITIONS sales"),
+ Row("country=CA/quarter=1") ::
+ Row("country=CA/quarter=2") ::
+ Row("country=KR/quarter=1") ::
+ Row("country=KR/quarter=2") ::
+ Row("country=KR/quarter=3") ::
+ Row("country=KR/quarter=4") ::
+ Row("country=US/quarter=1") ::
+ Row("country=US/quarter=2") ::
+ Row("country=US/quarter=3") ::
+ Row("country=US/quarter=4") :: Nil)
+
+ sql("ALTER TABLE sales DROP PARTITION (country < 'KR'), PARTITION
(quarter <= '1')")
+ checkAnswer(sql("SHOW PARTITIONS sales"),
+ Row("country=KR/quarter=2") ::
+ Row("country=KR/quarter=3") ::
+ Row("country=KR/quarter=4") ::
+ Row("country=US/quarter=2") ::
+ Row("country=US/quarter=3") ::
+ Row("country=US/quarter=4") :: Nil)
+
+ sql("ALTER TABLE sales DROP PARTITION (country='KR', quarter='4')")
+ sql("ALTER TABLE sales DROP PARTITION (country='US', quarter='3')")
+ checkAnswer(sql("SHOW PARTITIONS sales"),
+ Row("country=KR/quarter=2") ::
+ Row("country=KR/quarter=3") ::
+ Row("country=US/quarter=2") ::
+ Row("country=US/quarter=4") :: Nil)
+
+ sql("ALTER TABLE sales DROP PARTITION (quarter <= 2), PARTITION
(quarter >= '4')")
+ checkAnswer(sql("SHOW PARTITIONS sales"),
+ Row("country=KR/quarter=3") :: Nil)
+
+ val m = intercept[AnalysisException] {
+ sql("ALTER TABLE sales DROP PARTITION (quarter <= 4), PARTITION
(quarter <= '2')")
+ }.getMessage
+ // `PARTITION (quarter <= '2')` should raises exceptions because
`PARTITION (quarter <= 4)`
+ // already removes all partitions.
--- End diff --
I mean case 2. Current approach will drop the first spec successfully and
then the second spec will fail. I am not sure if this behavior is consistent
with Hive or not.
For the case of dropping partitions with only equal to spec, the current
behavior is collecting distinct matching partitions. So the overlapping specs
will not be a problem.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]