Skip to content

Commit

Permalink
[KYUUBI #5225] [KSHC] Unify the exception handling of v1 and v2 durin…
Browse files Browse the repository at this point in the history
…g dropDatabase

### _Why are the changes needed?_

This PR aims to unify the exception handling of v1 and v2 during dropDatabase

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [ ] [Run test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests) locally before make a pull request

### _Was this patch authored or co-authored using generative AI tooling?_

No

Closes #5225 from Yikf/hive-connector.

Closes #5225

3be33af [yikaifei] [KSHC] Improve test

Authored-by: yikaifei <[email protected]>
Signed-off-by: Bowen Liang <[email protected]>
  • Loading branch information
yikf authored and bowenliang123 committed Sep 1, 2023
1 parent c844f18 commit 0c987e9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,6 @@ class HiveTableCatalog(sparkSession: SparkSession)
withSQLConf(LEGACY_NON_IDENTIFIER_OUTPUT_CATALOG_NAME -> "true") {
namespace match {
case Array(db) if catalog.databaseExists(db) =>
if (catalog.listTables(db).nonEmpty && !cascade) {
throw new IllegalStateException(s"Namespace ${namespace.quoted} is not empty")
}
catalog.dropDatabase(db, ignoreIfNotExists = false, cascade)
true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract class KyuubiHiveTest extends QueryTest with Logging {
SupportsNamespaces.PROP_LOCATION,
SupportsNamespaces.PROP_OWNER)

protected def catalogName: String = "hive"
protected val catalogName: String = "hive"

override def beforeEach(): Unit = {
super.beforeAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ trait CreateNamespaceSuiteBase extends DDLCommandTestUtils {

class CreateNamespaceV2Suite extends CreateNamespaceSuiteBase {

override protected def catalogName: String = super.catalogName

override protected def catalogVersion: String = "Hive V2"

override protected def commandVersion: String = V2_COMMAND_VERSION
Expand All @@ -144,7 +142,7 @@ class CreateNamespaceV1Suite extends CreateNamespaceSuiteBase {

val SESSION_CATALOG_NAME: String = "spark_catalog"

override protected def catalogName: String = SESSION_CATALOG_NAME
override protected val catalogName: String = SESSION_CATALOG_NAME

override protected def catalogVersion: String = "V1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ package org.apache.kyuubi.spark.connector.hive.command
import org.apache.spark.sql.{AnalysisException, Row}
import org.apache.spark.sql.types.{StringType, StructType}

import org.apache.kyuubi.spark.connector.common.SparkUtils.SPARK_RUNTIME_VERSION
import org.apache.kyuubi.spark.connector.hive.command.DDLCommandTestUtils.{V1_COMMAND_VERSION, V2_COMMAND_VERSION}
import org.apache.kyuubi.util.AssertionUtils.interceptContains

trait DropNamespaceSuiteBase extends DDLCommandTestUtils {
override protected def command: String = "DROP NAMESPACE"
Expand Down Expand Up @@ -70,10 +72,14 @@ trait DropNamespaceSuiteBase extends DDLCommandTestUtils {
checkNamespace(Seq(namespace) ++ builtinNamespace)

// $catalog.ns.table is present, thus $catalog.ns cannot be dropped.
val e = intercept[IllegalStateException] {
interceptContains[AnalysisException] {
sql(s"DROP NAMESPACE $catalogName.$namespace")
}
assert(e.getMessage.contains(s"Namespace $namespace is not empty"))
}(if (SPARK_RUNTIME_VERSION >= "3.4") {
s"[SCHEMA_NOT_EMPTY] Cannot drop a schema `$namespace` because it contains objects"
} else {
"Use CASCADE option to drop a non-empty database"
})

sql(s"DROP TABLE $catalogName.$namespace.table")

// Now that $catalog.ns is empty, it can be dropped.
Expand All @@ -100,8 +106,6 @@ trait DropNamespaceSuiteBase extends DDLCommandTestUtils {

class DropNamespaceV2Suite extends DropNamespaceSuiteBase {

override protected def catalogName: String = super.catalogName

override protected def catalogVersion: String = "Hive V2"

override protected def commandVersion: String = V2_COMMAND_VERSION
Expand All @@ -111,7 +115,7 @@ class DropNamespaceV1Suite extends DropNamespaceSuiteBase {

val SESSION_CATALOG_NAME: String = "spark_catalog"

override protected def catalogName: String = SESSION_CATALOG_NAME
override protected val catalogName: String = SESSION_CATALOG_NAME

override protected def catalogVersion: String = "V1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ trait ShowTablesSuiteBase extends DDLCommandTestUtils {

class ShowTablesV2Suite extends ShowTablesSuiteBase {

override protected def catalogName: String = super.catalogName

override protected def catalogVersion: String = "Hive V2"

override protected def commandVersion: String = V2_COMMAND_VERSION
Expand All @@ -107,7 +105,7 @@ class ShowTablesV1Suite extends ShowTablesSuiteBase {

val SESSION_CATALOG_NAME: String = "spark_catalog"

override protected def catalogName: String = SESSION_CATALOG_NAME
override protected val catalogName: String = SESSION_CATALOG_NAME

override protected def catalogVersion: String = "V1"

Expand Down

0 comments on commit 0c987e9

Please sign in to comment.