@@ -23,11 +23,49 @@ import org.apache.spark.sql.execution.command
2323import org .apache .spark .sql .internal .SQLConf
2424
2525trait 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