Github user windpiger commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17287#discussion_r106065119
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala
 ---
    @@ -76,468 +118,499 @@ class SessionCatalogSuite extends PlanTest {
       }
     
       test("create databases using invalid names") {
    -    val catalog = new SessionCatalog(newEmptyCatalog())
    -    testInvalidName(name => catalog.createDatabase(newDb(name), 
ignoreIfExists = true))
    +    withSessionCatalog(EMPTY) { catalog =>
    +      testInvalidName(
    +        name => catalog.createDatabase(newDb(name), ignoreIfExists = true))
    +    }
       }
     
       test("get database when a database exists") {
    -    val catalog = new SessionCatalog(newBasicCatalog())
    -    val db1 = catalog.getDatabaseMetadata("db1")
    -    assert(db1.name == "db1")
    -    assert(db1.description.contains("db1"))
    +    withSessionCatalog() { catalog =>
    +      val db1 = catalog.getDatabaseMetadata("db1")
    +      assert(db1.name == "db1")
    +      assert(db1.description.contains("db1"))
    +    }
       }
     
       test("get database should throw exception when the database does not 
exist") {
    -    val catalog = new SessionCatalog(newBasicCatalog())
    -    intercept[NoSuchDatabaseException] {
    -      catalog.getDatabaseMetadata("db_that_does_not_exist")
    +    withSessionCatalog() { catalog =>
    +      intercept[NoSuchDatabaseException] {
    +        catalog.getDatabaseMetadata("db_that_does_not_exist")
    +      }
         }
       }
     
       test("list databases without pattern") {
    -    val catalog = new SessionCatalog(newBasicCatalog())
    -    assert(catalog.listDatabases().toSet == Set("default", "db1", "db2", 
"db3"))
    +    withSessionCatalog() { catalog =>
    +      assert(catalog.listDatabases().toSet == Set("default", "db1", "db2", 
"db3"))
    +    }
       }
     
       test("list databases with pattern") {
    -    val catalog = new SessionCatalog(newBasicCatalog())
    -    assert(catalog.listDatabases("db").toSet == Set.empty)
    -    assert(catalog.listDatabases("db*").toSet == Set("db1", "db2", "db3"))
    -    assert(catalog.listDatabases("*1").toSet == Set("db1"))
    -    assert(catalog.listDatabases("db2").toSet == Set("db2"))
    +    withSessionCatalog() { catalog =>
    +      assert(catalog.listDatabases("db").toSet == Set.empty)
    +      assert(catalog.listDatabases("db*").toSet == Set("db1", "db2", 
"db3"))
    +      assert(catalog.listDatabases("*1").toSet == Set("db1"))
    +      assert(catalog.listDatabases("db2").toSet == Set("db2"))
    +    }
       }
     
       test("drop database") {
    -    val catalog = new SessionCatalog(newBasicCatalog())
    -    catalog.dropDatabase("db1", ignoreIfNotExists = false, cascade = false)
    -    assert(catalog.listDatabases().toSet == Set("default", "db2", "db3"))
    +    withSessionCatalog() { catalog =>
    +      catalog.dropDatabase("db1", ignoreIfNotExists = false, cascade = 
false)
    +      assert(catalog.listDatabases().toSet == Set("default", "db2", "db3"))
    +    }
       }
     
       test("drop database when the database is not empty") {
         // Throw exception if there are functions left
    -    val externalCatalog1 = newBasicCatalog()
    -    val sessionCatalog1 = new SessionCatalog(externalCatalog1)
    -    externalCatalog1.dropTable("db2", "tbl1", ignoreIfNotExists = false, 
purge = false)
    -    externalCatalog1.dropTable("db2", "tbl2", ignoreIfNotExists = false, 
purge = false)
    -    intercept[AnalysisException] {
    -      sessionCatalog1.dropDatabase("db2", ignoreIfNotExists = false, 
cascade = false)
    +    withSessionCatalogAndExternal() { (catalog, externalCatalog) =>
    +      externalCatalog.dropTable("db2", "tbl1", ignoreIfNotExists = false, 
purge = false)
    +      externalCatalog.dropTable("db2", "tbl2", ignoreIfNotExists = false, 
purge = false)
    +      intercept[AnalysisException] {
    +        catalog.dropDatabase("db2", ignoreIfNotExists = false, cascade = 
false)
    +      }
         }
    -
    -    // Throw exception if there are tables left
    -    val externalCatalog2 = newBasicCatalog()
    -    val sessionCatalog2 = new SessionCatalog(externalCatalog2)
    -    externalCatalog2.dropFunction("db2", "func1")
    -    intercept[AnalysisException] {
    -      sessionCatalog2.dropDatabase("db2", ignoreIfNotExists = false, 
cascade = false)
    +    withSessionCatalogAndExternal() { (catalog, externalCatalog) =>
    +      // Throw exception if there are tables left
    +      externalCatalog.dropFunction("db2", "func1")
    +      intercept[AnalysisException] {
    +        catalog.dropDatabase("db2", ignoreIfNotExists = false, cascade = 
false)
    +      }
         }
     
    -    // When cascade is true, it should drop them
    -    val externalCatalog3 = newBasicCatalog()
    -    val sessionCatalog3 = new SessionCatalog(externalCatalog3)
    -    externalCatalog3.dropDatabase("db2", ignoreIfNotExists = false, 
cascade = true)
    -    assert(sessionCatalog3.listDatabases().toSet == Set("default", "db1", 
"db3"))
    +    withSessionCatalogAndExternal() { (catalog, externalCatalog) =>
    +      // When cascade is true, it should drop them
    +      externalCatalog.dropDatabase("db2", ignoreIfNotExists = false, 
cascade = true)
    +      assert(catalog.listDatabases().toSet == Set("default", "db1", "db3"))
    +    }
       }
     
       test("drop database when the database does not exist") {
    -    val catalog = new SessionCatalog(newBasicCatalog())
    -    intercept[NoSuchDatabaseException] {
    -      catalog.dropDatabase("db_that_does_not_exist", ignoreIfNotExists = 
false, cascade = false)
    +    withSessionCatalog() { catalog =>
    +      if (isHiveExternalCatalog) {
    --- End diff --
    
    ok ~ thanks~


---
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]

Reply via email to