Skip to content

Commit b6be4a9

Browse files
committed
Address PR comments
1 parent 0e96bf5 commit b6be4a9

File tree

3 files changed

+9
-53
lines changed

3 files changed

+9
-53
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,7 @@ class ResolveCatalogs(val catalogManager: CatalogManager)
104104
if (isView) {
105105
throw new AnalysisException("Renaming view is not supported in v2 catalogs.")
106106
}
107-
newNameParts match {
108-
case NonSessionCatalog(newCatalog, newName) =>
109-
if (catalog.name == newCatalog.name) {
110-
RenameTable(catalog.asTableCatalog, oldName.asIdentifier, newName.asIdentifier)
111-
} else {
112-
throw new AnalysisException(
113-
s"Cannot rename table in different catalogs: ${catalog.name} and ${newCatalog.name}")
114-
}
115-
case _ => throw new AnalysisException(
116-
"Renaming table cannot be performed across the session and non-session catalogs.")
117-
}
107+
RenameTable(catalog.asTableCatalog, oldName.asIdentifier, newNameParts.asIdentifier)
118108

119109
case DescribeTableStatement(
120110
nameParts @ NonSessionCatalog(catalog, tableName), partitionSpec, isExtended) =>

sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,7 @@ class ResolveSessionCatalog(
180180
AlterDatabaseSetLocationCommand(nameParts.head, location)
181181

182182
case RenameTableStatement(SessionCatalog(_, oldName), newNameParts, isView) =>
183-
newNameParts match {
184-
case SessionCatalog(_, newName) =>
185-
AlterTableRenameCommand(oldName.asTableIdentifier, newName.asTableIdentifier, isView)
186-
case _ => throw new AnalysisException(
187-
"Renaming table cannot be performed across the session and non-session catalogs.")
188-
}
183+
AlterTableRenameCommand(oldName.asTableIdentifier, newNameParts.asTableIdentifier, isView)
189184

190185
case DescribeTableStatement(
191186
nameParts @ SessionCatalog(catalog, tableName), partitionSpec, isExtended) =>

sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2SQLSuite.scala

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,50 +1536,21 @@ class DataSourceV2SQLSuite
15361536
}
15371537

15381538
test("AlterTable: rename table basic test") {
1539-
val t1 = "testcat.ns1.ns2.old"
1540-
val t2 = "testcat.ns1.new"
1541-
withTable(t1, t2) {
1542-
sql(s"CREATE TABLE $t1 USING foo AS SELECT id, data FROM source")
1539+
withTable("testcat.ns1.new") {
1540+
sql(s"CREATE TABLE testcat.ns1.ns2.old USING foo AS SELECT id, data FROM source")
15431541
checkAnswer(sql("SHOW TABLES FROM testcat.ns1.ns2"), Seq(Row("ns1.ns2", "old")))
15441542

1545-
sql(s"ALTER TABLE $t1 RENAME TO $t2")
1543+
sql(s"ALTER TABLE testcat.ns1.ns2.old RENAME TO ns1.new")
15461544
checkAnswer(sql("SHOW TABLES FROM testcat.ns1.ns2"), Seq.empty)
15471545
checkAnswer(sql("SHOW TABLES FROM testcat.ns1"), Seq(Row("ns1", "new")))
15481546
}
15491547
}
15501548

1551-
test("AlterTable: rename table fails when different v2 catalogs are used") {
1552-
val t1 = "testcat.ns1.ns2.t1"
1553-
val t2 = "testcat2.ns1.ns2.t2"
1554-
withTable(t1) {
1555-
sql(s"CREATE TABLE $t1 USING foo AS SELECT id, data FROM source")
1556-
1557-
val exception = intercept[AnalysisException] {
1558-
sql(s"ALTER TABLE $t1 RENAME TO $t2")
1559-
}
1560-
assert(exception.getMessage.contains(
1561-
"Cannot rename table in different catalogs: testcat and testcat2"))
1562-
}
1563-
}
1564-
1565-
test("AlterTable: rename table fails across session and non-session catalogs") {
1566-
val t1 = "t1"
1567-
val t2 = "testcat2.ns1.ns2.t2"
1568-
withTable(t1, t2) {
1569-
sql(s"CREATE TABLE $t1 USING csv AS SELECT id, data FROM source")
1570-
sql(s"CREATE TABLE $t2 USING foo AS SELECT id, data FROM source")
1571-
1572-
def assertFailure(oldTable: String, newTable: String) {
1573-
val exception = intercept[AnalysisException] {
1574-
sql(s"ALTER TABLE $oldTable RENAME TO $newTable")
1575-
}
1576-
assert(exception.getMessage.contains(
1577-
"Renaming table cannot be performed across the session and non-session catalogs."))
1578-
}
1579-
1580-
assertFailure(t1, t2) // session catalog to non-session catalog.
1581-
assertFailure(t2, t1) // non-session catalog to session catalog.
1549+
test("AlterTable: renaming views are not supported") {
1550+
val e = intercept[AnalysisException] {
1551+
sql(s"ALTER VIEW testcat.ns.tbl RENAME TO ns.view")
15821552
}
1553+
assert(e.getMessage.contains("Renaming view is not supported in v2 catalogs"))
15831554
}
15841555

15851556
test("ANALYZE TABLE") {

0 commit comments

Comments
 (0)