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 am wrong... There are other cases 
that may throw an `AnalysisException` and we should handle it



##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -439,12 +439,12 @@ class CatalogImpl(sparkSession: SparkSession) extends 
Catalog {
    * `Database` can be found.
    */
   override def getDatabase(dbName: String): Database = {
-    val namespace = resolveNamespace(dbName)
-    val plan = UnresolvedNamespace(namespace)
+    val plan = 
DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)

Review Comment:
   Yes, 
https://github.com/apache/spark/blob/9c21238ce0e6bec676213f4bad4bc1bf4ac16932/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala#L67-L68
 may not be sufficient for representing the getDatabase method



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to