Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/19086#discussion_r136724986
--- Diff:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala
---
@@ -357,25 +357,43 @@ abstract class SessionCatalogSuite extends
AnalysisTest {
test("rename table") {
withBasicCatalog { catalog =>
+ catalog.setCurrentDatabase("db2")
assert(catalog.externalCatalog.listTables("db2").toSet ==
Set("tbl1", "tbl2"))
catalog.renameTable(TableIdentifier("tbl1", Some("db2")),
TableIdentifier("tblone"))
assert(catalog.externalCatalog.listTables("db2").toSet ==
Set("tblone", "tbl2"))
catalog.renameTable(TableIdentifier("tbl2", Some("db2")),
TableIdentifier("tbltwo"))
assert(catalog.externalCatalog.listTables("db2").toSet ==
Set("tblone", "tbltwo"))
- // Rename table without explicitly specifying database
+
+ // Current database will be used when rename table without
explicitly specifying database
catalog.setCurrentDatabase("db2")
catalog.renameTable(TableIdentifier("tbltwo"),
TableIdentifier("table_two"))
assert(catalog.externalCatalog.listTables("db2").toSet ==
Set("tblone", "table_two"))
- // Renaming "db2.tblone" to "db1.tblones" should fail because
databases don't match
+
+ // Table will be moved across databases when its database is
different from the destination.
+ catalog.renameTable(
+ TableIdentifier("table_two", None), TableIdentifier("tabletwo",
Some("db1")))
+ assert(catalog.externalCatalog.listTables("db1").toSet ==
Set("tabletwo"))
+ assert(catalog.externalCatalog.listTables("db2").toSet ==
Set("tblone"))
+
+ catalog.renameTable(
+ TableIdentifier("tabletwo", Some("db1")),
TableIdentifier("table_two", None))
+ assert(catalog.externalCatalog.listTables("db2").toSet ==
Set("tblone", "table_two"))
+
+ catalog.renameTable(
+ TableIdentifier("tblone", Some("db2")), TableIdentifier("tblone",
Some("db1")))
+ assert(catalog.externalCatalog.listTables("db1").toSet ==
Set("tblone"))
+ assert(catalog.externalCatalog.listTables("db2").toSet ==
Set("table_two"))
+
+ // Renaming "db2.tblone" to "db1.tblones" should fail because table
cannot be found.
intercept[AnalysisException] {
--- End diff --
add an assert to check the message.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]