diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalog.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalog.scala index 0c144266411a..efbc9dd75589 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalog.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalog.scala @@ -24,7 +24,7 @@ import scala.collection.JavaConverters._ import scala.collection.mutable import org.apache.spark.sql.catalyst.{FunctionIdentifier, SQLConfHelper, TableIdentifier} -import org.apache.spark.sql.catalyst.analysis.{NoSuchTableException, TableAlreadyExistsException} +import org.apache.spark.sql.catalyst.analysis.{NoSuchDatabaseException, NoSuchTableException, TableAlreadyExistsException} import org.apache.spark.sql.catalyst.catalog.{CatalogDatabase, CatalogTable, CatalogTableType, CatalogUtils, SessionCatalog} import org.apache.spark.sql.connector.catalog.{CatalogManager, CatalogV2Util, FunctionCatalog, Identifier, NamespaceChange, SupportsNamespaces, Table, TableCatalog, TableChange, V1Table} import org.apache.spark.sql.connector.catalog.NamespaceChange.RemoveProperty @@ -245,7 +245,12 @@ class V2SessionCatalog(catalog: SessionCatalog) override def loadNamespaceMetadata(namespace: Array[String]): util.Map[String, String] = { namespace match { case Array(db) => - catalog.getDatabaseMetadata(db).toMetadata + try { + catalog.getDatabaseMetadata(db).toMetadata + } catch { + case _: NoSuchDatabaseException => + throw QueryCompilationErrors.noSuchNamespaceError(namespace) + } case _ => throw QueryCompilationErrors.noSuchNamespaceError(namespace) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/DescribeNamespaceSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/DescribeNamespaceSuite.scala index aa4547db1e62..e71b311d2414 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/DescribeNamespaceSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/DescribeNamespaceSuite.scala @@ -59,5 +59,6 @@ trait DescribeNamespaceSuiteBase extends command.DescribeNamespaceSuiteBase * table catalog. */ class DescribeNamespaceSuite extends DescribeNamespaceSuiteBase with CommandSuiteBase { + override def notFoundMsgPrefix: String = if (conf.useV1Command) "Database" else "Namespace" override def commandVersion: String = super[DescribeNamespaceSuiteBase].commandVersion } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalogSuite.scala index af0eafbc805e..d37d5a96c656 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalogSuite.scala @@ -850,7 +850,7 @@ class V2SessionCatalogNamespaceSuite extends V2SessionCatalogBaseSuite { test("loadNamespaceMetadata: fail missing namespace") { val catalog = newCatalog() - val exc = intercept[NoSuchDatabaseException] { + val exc = intercept[NoSuchNamespaceException] { catalog.loadNamespaceMetadata(testNs) } diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/command/DescribeNamespaceSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/command/DescribeNamespaceSuite.scala index be8423fca0b4..f730cad03ba8 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/command/DescribeNamespaceSuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/command/DescribeNamespaceSuite.scala @@ -24,5 +24,6 @@ import org.apache.spark.sql.execution.command.v1 * table catalog. */ class DescribeNamespaceSuite extends v1.DescribeNamespaceSuiteBase with CommandSuiteBase { + override def notFoundMsgPrefix: String = if (conf.useV1Command) "Database" else "Namespace" override def commandVersion: String = super[DescribeNamespaceSuiteBase].commandVersion }