From fb95f9c6c65288a7ebd19022db664e7cb879fab9 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Wed, 22 Jun 2022 00:10:33 +0530 Subject: [PATCH 1/3] V2SessionCatalog should not throw NoSuchDatabaseException in loadNamespaceMetadata --- .../spark/sql/execution/datasources/v2/V2SessionCatalog.scala | 2 +- .../sql/execution/datasources/v2/V2SessionCatalogSuite.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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..c2a1770e6124 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 @@ -244,7 +244,7 @@ class V2SessionCatalog(catalog: SessionCatalog) override def loadNamespaceMetadata(namespace: Array[String]): util.Map[String, String] = { namespace match { - case Array(db) => + case Array(db) if catalog.databaseExists(db) => catalog.getDatabaseMetadata(db).toMetadata case _ => 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) } From c779f3f2c82e6c722fbae602f3c9324ff7e00c24 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Wed, 22 Jun 2022 13:11:29 +0530 Subject: [PATCH 2/3] fix test failures --- .../spark/sql/execution/command/v1/DescribeNamespaceSuite.scala | 1 + .../sql/hive/execution/command/DescribeNamespaceSuite.scala | 1 + 2 files changed, 2 insertions(+) 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/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 } From 3c7e3fa782917a874bccfcc30af7872cbfee4294 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Thu, 23 Jun 2022 00:26:51 +0530 Subject: [PATCH 3/3] address review feedback --- .../execution/datasources/v2/V2SessionCatalog.scala | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 c2a1770e6124..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 @@ -244,8 +244,13 @@ class V2SessionCatalog(catalog: SessionCatalog) override def loadNamespaceMetadata(namespace: Array[String]): util.Map[String, String] = { namespace match { - case Array(db) if catalog.databaseExists(db) => - catalog.getDatabaseMetadata(db).toMetadata + case Array(db) => + try { + catalog.getDatabaseMetadata(db).toMetadata + } catch { + case _: NoSuchDatabaseException => + throw QueryCompilationErrors.noSuchNamespaceError(namespace) + } case _ => throw QueryCompilationErrors.noSuchNamespaceError(namespace)