Skip to content

Commit 6db2b3e

Browse files
committed
Test that target partition exists
1 parent aa602e0 commit 6db2b3e

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/AlterTableRenamePartitionSuite.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.apache.spark.sql.execution.command.v1
1919

2020
import org.apache.spark.sql.{AnalysisException, Row}
21-
import org.apache.spark.sql.catalyst.analysis.{NoSuchPartitionException, NoSuchTableException}
21+
import org.apache.spark.sql.catalyst.analysis.{NoSuchPartitionException, NoSuchTableException, PartitionAlreadyExistsException}
2222
import org.apache.spark.sql.execution.command
2323
import org.apache.spark.sql.internal.SQLConf
2424

@@ -155,4 +155,16 @@ class AlterTableRenamePartitionSuite
155155
}
156156
}
157157
}
158+
159+
test("target partition exists") {
160+
withNamespaceAndTable("ns", "tbl") { t =>
161+
createSinglePartTable(t)
162+
sql(s"INSERT INTO $t PARTITION (id = 2) SELECT 'def'")
163+
checkPartitions(t, Map("id" -> "1"), Map("id" -> "2"))
164+
val errMsg = intercept[PartitionAlreadyExistsException] {
165+
sql(s"ALTER TABLE $t PARTITION (id = 1) RENAME TO PARTITION (id = 2)")
166+
}.getMessage
167+
assert(errMsg.contains("Partition already exists"))
168+
}
169+
}
158170
}

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/command/AlterTableRenamePartitionSuite.scala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,23 @@
1717

1818
package org.apache.spark.sql.hive.execution.command
1919

20+
import org.apache.spark.sql.AnalysisException
2021
import org.apache.spark.sql.execution.command.v1
2122

2223
class AlterTableRenamePartitionSuite
2324
extends v1.AlterTableRenamePartitionSuiteBase
24-
with CommandSuiteBase
25+
with CommandSuiteBase {
26+
27+
test("target partition exists") {
28+
withNamespaceAndTable("ns", "tbl") { t =>
29+
createSinglePartTable(t)
30+
sql(s"INSERT INTO $t PARTITION (id = 2) SELECT 'def'")
31+
checkPartitions(t, Map("id" -> "1"), Map("id" -> "2"))
32+
// TODO(SPARK-33862): Throw PartitionAlreadyExistsException
33+
val errMsg = intercept[AnalysisException] {
34+
sql(s"ALTER TABLE $t PARTITION (id = 1) RENAME TO PARTITION (id = 2)")
35+
}.getMessage
36+
assert(errMsg.contains("Partition already exists"))
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)