pan3793 commented on code in PR #57468:
URL: https://github.com/apache/spark/pull/57468#discussion_r3642539301


##########
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetSchemasOperation.scala:
##########
@@ -78,34 +78,38 @@ private[hive] class SparkGetSchemasOperation(
         // filtering deferred).
         val resolvedCatalog = catalogManager.currentCatalog
         val catalogNameValue = resolvedCatalog.name()
+        // Use SupportsNamespaces uniformly for all catalogs including the 
session
+        // catalog (V2SessionCatalog implements SupportsNamespaces). This 
avoids
+        // assuming that a spark_catalog override delegates to the built-in 
session
+        // catalog.
+        resolvedCatalog match {
+          case nsCatalog: SupportsNamespaces =>
+            // NOTE: The DSv2 SupportsNamespaces.listNamespaces() API does not 
accept a
+            // pattern argument, so filtering is applied client-side. This is 
a potential
+            // performance consideration for catalogs with a very large number 
of
+            // namespaces.
+            val databasePattern = Pattern.compile(
+              CLIServiceUtils.patternToRegex(schemaName))
+            nsCatalog.listNamespaces().foreach { ns =>
+              // Only top-level namespaces (depth=1) are exposed as JDBC 
schemas.
+              val nsName = ns.head
+              if (schemaName == null || schemaName.isEmpty ||
+                  databasePattern.matcher(nsName).matches()) {
+                rowSet.addRow(Array[AnyRef](nsName, catalogNameValue))
+              }
+            }
+          case _ =>
+            // Catalog doesn't support namespaces -- return empty
+        }
+        // The global temp view database is a Spark pseudo-namespace that only 
exists
+        // for the session catalog; it is not a real catalog namespace.
         if (catalogNameValue == CatalogManager.SESSION_CATALOG_NAME) {
-          // For spark_catalog, use the V1 SessionCatalog directly 
(transparent delegation)
-          catalog.listDatabases(schemaPattern).foreach { dbName =>
-            rowSet.addRow(Array[AnyRef](dbName, catalogNameValue))
-          }
-          // Global temp view database is only relevant for spark_catalog
           val globalTempViewDb = catalog.globalTempDatabase
           val databasePattern = 
Pattern.compile(CLIServiceUtils.patternToRegex(schemaName))
           if (schemaName == null || schemaName.isEmpty ||
               databasePattern.matcher(globalTempViewDb).matches()) {
             rowSet.addRow(Array[AnyRef](globalTempViewDb, catalogNameValue))

Review Comment:
   What if the catalog has a real database named `globalTempViewDb`?



-- 
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