Skip to content

Commit aa602e0

Browse files
committed
Move v1 tests
1 parent a1ba687 commit aa602e0

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import org.apache.spark.internal.config
2929
import org.apache.spark.internal.config.RDD_PARALLEL_LISTING_THRESHOLD
3030
import org.apache.spark.sql.{AnalysisException, QueryTest, Row, SaveMode}
3131
import org.apache.spark.sql.catalyst.{FunctionIdentifier, QualifiedTableName, TableIdentifier}
32-
import org.apache.spark.sql.catalyst.analysis.{FunctionRegistry, NoSuchDatabaseException, NoSuchFunctionException, NoSuchPartitionException, NoSuchTableException, TempTableAlreadyExistsException}
32+
import org.apache.spark.sql.catalyst.analysis.{FunctionRegistry, NoSuchDatabaseException, NoSuchFunctionException, NoSuchPartitionException, TempTableAlreadyExistsException}
3333
import org.apache.spark.sql.catalyst.catalog._
3434
import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec
3535
import org.apache.spark.sql.connector.catalog.SupportsNamespaces.PROP_OWNER

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

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,49 @@ import org.apache.spark.sql.execution.command
2323
import org.apache.spark.sql.internal.SQLConf
2424

2525
trait AlterTableRenamePartitionSuiteBase extends command.AlterTableRenamePartitionSuiteBase {
26-
private def createSinglePartTable(t: String): Unit = {
26+
protected def createSinglePartTable(t: String): Unit = {
2727
sql(s"CREATE TABLE $t (id bigint, data string) $defaultUsing PARTITIONED BY (id)")
2828
sql(s"INSERT INTO $t PARTITION (id = 1) SELECT 'abc'")
2929
}
3030

31+
test("rename without explicitly specifying database") {
32+
val t = "tbl"
33+
withTable(t) {
34+
createSinglePartTable(t)
35+
checkPartitions(t, Map("id" -> "1"))
36+
37+
sql(s"ALTER TABLE $t PARTITION (id = 1) RENAME TO PARTITION (id = 2)")
38+
checkPartitions(t, Map("id" -> "2"))
39+
checkAnswer(sql(s"SELECT id, data FROM $t"), Row(2, "abc"))
40+
}
41+
}
42+
43+
test("table to alter does not exist") {
44+
withNamespace(s"$catalog.ns") {
45+
sql(s"CREATE NAMESPACE $catalog.ns")
46+
val errMsg = intercept[NoSuchTableException] {
47+
sql(s"ALTER TABLE $catalog.ns.no_tbl PARTITION (id=1) RENAME TO PARTITION (id=2)")
48+
}.getMessage
49+
assert(errMsg.contains("Table or view 'no_tbl' not found"))
50+
}
51+
}
52+
53+
test("partition to rename does not exist") {
54+
withNamespaceAndTable("ns", "tbl") { t =>
55+
createSinglePartTable(t)
56+
checkPartitions(t, Map("id" -> "1"))
57+
val errMsg = intercept[NoSuchPartitionException] {
58+
sql(s"ALTER TABLE $t PARTITION (id = 3) RENAME TO PARTITION (id = 2)")
59+
}.getMessage
60+
assert(errMsg.contains("Partition not found in table"))
61+
}
62+
}
63+
}
64+
65+
class AlterTableRenamePartitionSuite
66+
extends AlterTableRenamePartitionSuiteBase
67+
with CommandSuiteBase {
68+
3169
test("single part partition") {
3270
withNamespaceAndTable("ns", "tbl") { t =>
3371
createSinglePartTable(t)
@@ -97,39 +135,6 @@ trait AlterTableRenamePartitionSuiteBase extends command.AlterTableRenamePartiti
97135
}
98136
}
99137

100-
test("rename without explicitly specifying database") {
101-
val t = "tbl"
102-
withTable(t) {
103-
createSinglePartTable(t)
104-
checkPartitions(t, Map("id" -> "1"))
105-
106-
sql(s"ALTER TABLE $t PARTITION (id = 1) RENAME TO PARTITION (id = 2)")
107-
checkPartitions(t, Map("id" -> "2"))
108-
checkAnswer(sql(s"SELECT id, data FROM $t"), Row(2, "abc"))
109-
}
110-
}
111-
112-
test("table to alter does not exist") {
113-
withNamespace(s"$catalog.ns") {
114-
sql(s"CREATE NAMESPACE $catalog.ns")
115-
val errMsg = intercept[NoSuchTableException] {
116-
sql(s"ALTER TABLE $catalog.ns.no_tbl PARTITION (id=1) RENAME TO PARTITION (id=2)")
117-
}.getMessage
118-
assert(errMsg.contains("Table or view 'no_tbl' not found"))
119-
}
120-
}
121-
122-
test("partition to rename does not exist") {
123-
withNamespaceAndTable("ns", "tbl") { t =>
124-
createSinglePartTable(t)
125-
checkPartitions(t, Map("id" -> "1"))
126-
val errMsg = intercept[NoSuchPartitionException] {
127-
sql(s"ALTER TABLE $t PARTITION (id = 3) RENAME TO PARTITION (id = 2)")
128-
}.getMessage
129-
assert(errMsg.contains("Partition not found in table"))
130-
}
131-
}
132-
133138
test("partition spec in RENAME PARTITION should be case insensitive") {
134139
withNamespaceAndTable("ns", "tbl") { t =>
135140
createSinglePartTable(t)
@@ -151,7 +156,3 @@ trait AlterTableRenamePartitionSuiteBase extends command.AlterTableRenamePartiti
151156
}
152157
}
153158
}
154-
155-
class AlterTableRenamePartitionSuite
156-
extends AlterTableRenamePartitionSuiteBase
157-
with CommandSuiteBase

0 commit comments

Comments
 (0)