Github user gatorsmile commented on a diff in the pull request: https://github.com/apache/spark/pull/19086#discussion_r136747159 --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala --- @@ -418,6 +439,42 @@ abstract class SessionCatalogSuite extends AnalysisTest { } } + test("rename global temp view") { + withBasicCatalog { catalog => + val globalTempTable = Range(1, 10, 2, 10) + catalog.createGlobalTempView("tbl1", globalTempTable, overrideIfExists = false) + assert(catalog.getGlobalTempView("tbl1") == Option(globalTempTable)) + assert(catalog.externalCatalog.listTables("db2").toSet == Set("tbl1", "tbl2")) + // If database is not specified, global temp view will not be renamed + catalog.setCurrentDatabase("db1") + val thrown1 = intercept[AnalysisException] { + catalog.renameTable(TableIdentifier("tbl1"), TableIdentifier("tblone")) + } + assert(thrown1.getMessage.contains("Table or view 'tbl1' not found in database 'db1'")) + catalog.setCurrentDatabase("db2") + catalog.renameTable(TableIdentifier("tbl1"), TableIdentifier("tblone")) + assert(catalog.getGlobalTempView("tbl1") == Option(globalTempTable)) + assert(catalog.externalCatalog.listTables("db2").toSet == Set("tblone", "tbl2")) + // Moving global temp view to another database is forbidden + val thrown2 = intercept[AnalysisException] { + catalog.renameTable( + TableIdentifier("tbl1", Some("global_temp")), TableIdentifier("tbl3", Some("db2"))) + } + assert(thrown2.getMessage.contains("Cannot change database of table 'tbl1'")) + // Moving table from regular database to be a global temp view is forbidden + val thrown3 = intercept[AnalysisException] { + catalog.renameTable( + TableIdentifier("tbl2", Some("db2")), TableIdentifier("tbltwo", Some("global_temp"))) + } --- End diff -- Normally, we put `.getMessage` here. Thus, we can make the next line shorter.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org