You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "heyihong (via GitHub)" <gi...@apache.org> on 2023/11/23 13:34:27 UTC

Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation to use DescribeNamespace [spark]

heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1403361939


##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -516,18 +516,11 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
    * Checks if the database with the specified name exists.
    */
   override def databaseExists(dbName: String): Boolean = {
-    // To maintain backwards compatibility, we first treat the input is a simple dbName and check
-    // if sessionCatalog contains it. If no, we try to parse it, resolve catalog and namespace,
-    // and check if namespace exists in the catalog.
-    if (!sessionCatalog.databaseExists(dbName)) {
-      val plan = UnresolvedNamespace(parseIdent(dbName))
-      sparkSession.sessionState.executePlan(plan).analyzed match {
-        case ResolvedNamespace(catalog: SupportsNamespaces, ns) =>
-          catalog.namespaceExists(ns.toArray)
-        case _ => true
-      }
-    } else {
-      true
+    val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
+    sparkSession.sessionState.executePlan(plan).analyzed match {

Review Comment:
   Originally, I thought `AnalysisException` won't be threw when the database is missing since https://github.com/apache/spark/blob/9c21238ce0e6bec676213f4bad4bc1bf4ac16932/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala#L67-L68 only checks whether Catalog exists. But I was wrong... There are other cases that may throw an `AnalysisException` and we should handle it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org