Skip to content

Commit e100834

Browse files
committed
Move the test to the common trait
1 parent 1554977 commit e100834

File tree

4 files changed

+20
-55
lines changed

4 files changed

+20
-55
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.scalactic.source.Position
2121
import org.scalatest.Tag
2222

2323
import org.apache.spark.sql.{AnalysisException, QueryTest, Row}
24+
import org.apache.spark.sql.catalyst.analysis.PartitionsAlreadyExistException
2425
import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec
2526
import org.apache.spark.sql.execution.datasources.PartitioningUtils
2627
import org.apache.spark.sql.internal.SQLConf
@@ -184,4 +185,21 @@ trait AlterTableAddPartitionSuiteBase extends QueryTest with SQLTestUtils {
184185
"The spec (part0) must match the partition spec (part0, part1)"))
185186
}
186187
}
188+
189+
test("partition already exists") {
190+
withNsTable("ns", "tbl") { t =>
191+
sql(s"CREATE TABLE $t (id bigint, data string) $defaultUsing PARTITIONED BY (id)")
192+
sql(s"ALTER TABLE $t ADD PARTITION (id=2) LOCATION 'loc1'")
193+
194+
val errMsg = intercept[PartitionsAlreadyExistException] {
195+
sql(s"ALTER TABLE $t ADD PARTITION (id=1) LOCATION 'loc'" +
196+
" PARTITION (id=2) LOCATION 'loc1'")
197+
}.getMessage
198+
assert(errMsg.contains("The following partitions already exists"))
199+
200+
sql(s"ALTER TABLE $t ADD IF NOT EXISTS PARTITION (id=1) LOCATION 'loc'" +
201+
" PARTITION (id=2) LOCATION 'loc1'")
202+
checkPartitions(t, Map("id" -> "1"), Map("id" -> "2"))
203+
}
204+
}
187205
}

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

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

20-
import org.apache.spark.sql.catalyst.analysis.PartitionsAlreadyExistException
2120
import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec
2221
import org.apache.spark.sql.connector.catalog.CatalogManager
2322
import org.apache.spark.sql.execution.command
@@ -44,21 +43,4 @@ trait AlterTableAddPartitionSuiteBase extends command.AlterTableAddPartitionSuit
4443
}
4544
}
4645

47-
class AlterTableAddPartitionSuite extends AlterTableAddPartitionSuiteBase with SharedSparkSession {
48-
test("partition already exists") {
49-
withNsTable("ns", "tbl") { t =>
50-
sql(s"CREATE TABLE $t (id bigint, data string) $defaultUsing PARTITIONED BY (id)")
51-
sql(s"ALTER TABLE $t ADD PARTITION (id=2) LOCATION 'loc1'")
52-
53-
val errMsg = intercept[PartitionsAlreadyExistException] {
54-
sql(s"ALTER TABLE $t ADD PARTITION (id=1) LOCATION 'loc'" +
55-
" PARTITION (id=2) LOCATION 'loc1'")
56-
}.getMessage
57-
assert(errMsg.contains("The following partitions already exists"))
58-
59-
sql(s"ALTER TABLE $t ADD IF NOT EXISTS PARTITION (id=1) LOCATION 'loc'" +
60-
" PARTITION (id=2) LOCATION 'loc1'")
61-
checkPartitions(t, Map("id" -> "1"), Map("id" -> "2"))
62-
}
63-
}
64-
}
46+
class AlterTableAddPartitionSuite extends AlterTableAddPartitionSuiteBase with SharedSparkSession

sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/AlterTableAddPartitionSuite.scala

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package org.apache.spark.sql.execution.command.v2
1919

2020
import org.apache.spark.SparkConf
2121
import org.apache.spark.sql.AnalysisException
22-
import org.apache.spark.sql.catalyst.analysis.{PartitionsAlreadyExistException, ResolvePartitionSpec}
22+
import org.apache.spark.sql.catalyst.analysis.ResolvePartitionSpec
2323
import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec
2424
import org.apache.spark.sql.connector.{InMemoryPartitionTable, InMemoryPartitionTableCatalog, InMemoryTableCatalog}
2525
import org.apache.spark.sql.connector.catalog.{CatalogV2Implicits, Identifier}
@@ -60,23 +60,6 @@ class AlterTableAddPartitionSuite
6060
assert(partMetadata.get("location") === expected)
6161
}
6262

63-
test("partition already exists") {
64-
withNsTable("ns", "tbl") { t =>
65-
sql(s"CREATE TABLE $t (id bigint, data string) $defaultUsing PARTITIONED BY (id)")
66-
sql(s"ALTER TABLE $t ADD PARTITION (id=2) LOCATION 'loc1'")
67-
68-
val errMsg = intercept[PartitionsAlreadyExistException] {
69-
sql(s"ALTER TABLE $t ADD PARTITION (id=1) LOCATION 'loc'" +
70-
" PARTITION (id=2) LOCATION 'loc1'")
71-
}.getMessage
72-
assert(errMsg.contains("The following partitions already exists"))
73-
74-
sql(s"ALTER TABLE $t ADD IF NOT EXISTS PARTITION (id=1) LOCATION 'loc'" +
75-
" PARTITION (id=2) LOCATION 'loc1'")
76-
checkPartitions(t, Map("id" -> "1"), Map("id" -> "2"))
77-
}
78-
}
79-
8063
test("SPARK-33650: add partition into a table which doesn't support partition management") {
8164
withNsTable("ns", "tbl", s"non_part_$catalog") { t =>
8265
sql(s"CREATE TABLE $t (id bigint, data string) $defaultUsing")

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

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

20-
import org.apache.spark.sql.AnalysisException
2120
import org.apache.spark.sql.execution.command.v1
2221
import org.apache.spark.sql.hive.test.TestHiveSingleton
2322

@@ -26,21 +25,4 @@ class AlterTableAddPartitionSuite
2625
with TestHiveSingleton {
2726
override def version: String = "Hive V1"
2827
override def defaultUsing: String = "USING HIVE"
29-
30-
test("partition already exists") {
31-
withNsTable("ns", "tbl") { t =>
32-
sql(s"CREATE TABLE $t (id bigint, data string) $defaultUsing PARTITIONED BY (id)")
33-
sql(s"ALTER TABLE $t ADD PARTITION (id=2) LOCATION 'loc1'")
34-
35-
val errMsg = intercept[AnalysisException] {
36-
sql(s"ALTER TABLE $t ADD PARTITION (id=1) LOCATION 'loc'" +
37-
" PARTITION (id=2) LOCATION 'loc1'")
38-
}.getMessage
39-
assert(errMsg.contains("already exists"))
40-
41-
sql(s"ALTER TABLE $t ADD IF NOT EXISTS PARTITION (id=1) LOCATION 'loc'" +
42-
" PARTITION (id=2) LOCATION 'loc1'")
43-
checkPartitions(t, Map("id" -> "1"), Map("id" -> "2"))
44-
}
45-
}
4628
}

0 commit comments

Comments
 (0)