Skip to content

Commit 56c9bad

Browse files
wangyumGitHub Enterprise
authored andcommitted
[CARMEL-6511] Disable rename temp table (#1254)
* Update tables.scala * Update tables.scala * Update tables.scala * Update TemporaryTableSuite.scala
1 parent 71489e9 commit 56c9bad

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,12 @@ case class AlterTableRenameCommand(
247247
val catalog = sparkSession.sessionState.catalog
248248
// If this is a temp view, just rename the view.
249249
// Otherwise, if this is a real table, we also need to uncache and invalidate the table.
250-
if (catalog.isTemporaryView(oldName) || catalog.isTemporaryTable(oldName)) {
250+
if (catalog.isTemporaryView(oldName)) {
251251
catalog.renameTable(oldName, newName)
252252
} else {
253253
val table = catalog.getTableMetadata(oldName)
254+
DDLUtils.verifyOperationAllowableOnTempTable(catalog, table.identifier,
255+
"AlterTableRenameCommand")
254256
DDLUtils.verifyAlterTableType(catalog, table, isView)
255257

256258
DDLUtils.ddlLockSafe(sparkSession.sessionState, "Alter Table Rename", !isView) {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,10 @@ class TemporaryTableSuite extends QueryTest with SharedSparkSession {
274274
test("test rename temporary table") {
275275
withTempTable("t1", "t2") {
276276
sql("CREATE TEMPORARY TABLE t1 USING parquet AS SELECT 1")
277-
sql("ALTER TABLE t1 RENAME TO t2")
278-
assert(spark.sessionState.catalog.getTempTable("t1").isEmpty)
279-
assert(spark.sessionState.catalog.getTempTable("t2").nonEmpty)
277+
val e = intercept[AnalysisException] {
278+
sql("ALTER TABLE t1 RENAME TO t2")
279+
}
280+
assert(e.message.contains("Operation not allowed"))
280281
}
281282
}
282283

@@ -415,7 +416,7 @@ class TemporaryTableSuite extends QueryTest with SharedSparkSession {
415416
}
416417
}
417418

418-
test("rename temporary table name should case insensitive") {
419+
ignore("rename temporary table name should case insensitive") {
419420
withTempTable("test_TMP", "test_TMP2") {
420421
sql("CREATE TEMPORARY TABLE test_TMP (id INT) USING PARQUET")
421422
sql("ALTER TABLE test_TMP rename to test_TMP2")

0 commit comments

Comments
 (0)