You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "yadavay-amzn (via GitHub)" <gi...@apache.org> on 2026/07/23 16:54:41 UTC

[PR] [SPARK-57518][SQL][FOLLOWUP] List ThriftServer schemas via SupportsNamespaces instead of special-casing spark_catalog [spark]

yadavay-amzn opened a new pull request, #57468:
URL: https://github.com/apache/spark/pull/57468

   ### What changes were proposed in this pull request?
   
   Follow-up to #56627 ([SPARK-57518](https://issues.apache.org/jira/browse/SPARK-57518)), addressing review feedback.
   
   `SparkGetSchemasOperation` special-cased the session catalog: when the current catalog was `spark_catalog`, it listed databases via the V1 `SessionCatalog.listDatabases`, and only used the DSv2 `SupportsNamespaces.listNamespaces()` path for other catalogs. That assumed a `spark_catalog` override (e.g. a custom `CatalogExtension`) delegates its namespace listing to the built-in session catalog, which is not guaranteed.
   
   This change lists schemas uniformly through the current catalog's `SupportsNamespaces.listNamespaces()` for all catalogs, and drops the `spark_catalog` special-case. The built-in `V2SessionCatalog` also implements `SupportsNamespaces`, so the default session catalog keeps working, and an overridden `spark_catalog` now correctly reports its own namespaces. The `global_temp` database is retained as a special case for the session catalog only, since it is a Spark pseudo-namespace rather than a real catalog namespace.
   
   ### Why are the changes needed?
   
   The previous approach could report the wrong schemas for a `spark_catalog` override that does not delegate namespace listing to the built-in session catalog.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Behavior change on the DSv2 metadata path only: schema-name matching now uses JDBC pattern semantics (`%` and `_`), consistent with `DatabaseMetaData.getSchemas`. Hive-style glob (`*`) is not a JDBC wildcard and is no longer matched on this path.
   
   ### Performance consideration
   
   `SupportsNamespaces.listNamespaces()` has no schema-pattern argument (unlike V1 `listDatabases(pattern)`), so the schema pattern is applied client-side. For a catalog with many namespaces this lists all top-level namespaces and then filters, rather than pushing the pattern down. The current DSv2 API does not support pushing the pattern down; if this becomes a concern, a DSv2 API enhancement to accept a pattern would be a separate improvement. Raising it here for discussion.
   
   ### How was this patch tested?
   
   `SparkMetadataOperationSuite`: verifies `spark_catalog` lists its namespaces via `SupportsNamespaces` and that `global_temp` still appears. Existing getSchemas coverage passes. `SparkGetTablesOperation`/`SparkGetColumnsOperation` do not have this special-case and are unchanged.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Authored with assistance by Claude Opus 4.8.
   


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


Re: [PR] [SPARK-57518][SQL][FOLLOWUP] List ThriftServer schemas via SupportsNamespaces instead of special-casing spark_catalog [spark]

Posted by "yadavay-amzn (via GitHub)" <gi...@apache.org>.
yadavay-amzn commented on code in PR #57468:
URL: https://github.com/apache/spark/pull/57468#discussion_r3677055664


##########
sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkMetadataOperationSuite.scala:
##########
@@ -55,7 +56,10 @@ class SparkMetadataOperationSuite extends HiveThriftServer2TestBase {
         checkResult(metaData.getSchemas(null, pattern), dbs ++ dbDflts)
       }
 
-      Seq("db%", "db*") foreach { pattern =>
+      // Note: "db*" was removed because `*` is not a valid JDBC wildcard character
+      // (only `%` and `_` are); on the DSv2 SupportsNamespaces path it is treated as a

Review Comment:
   You're right. `patternToRegex` now escapes the regex metacharacters (`\.[]{}()*+?^$|`) so only `%`/`_` stay as wildcards: `db*` and a bare `*` are literals now (no match, no throw), while `db%`/`db_` still work. Added the counterexamples to the suite (`db*`, `.*`, `db.`, `*` all return empty). One knock-on: `SparkGetFunctionsOperation` was passing `patternToRegex(...)` into `listFunctions`, which actually wants `filterPattern`'s `*`-wildcard semantics (its tests use `overla*`), so escaping `*` would have broken it. I dropped the `patternToRegex` call there and pass the pattern straight to `listFunctions`, which is what it expected.



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


Re: [PR] [SPARK-57518][SQL][FOLLOWUP] List ThriftServer schemas via SupportsNamespaces instead of special-casing spark_catalog [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #57468:
URL: https://github.com/apache/spark/pull/57468#discussion_r3688658937


##########
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetFunctionsOperation.scala:
##########
@@ -60,7 +60,7 @@ private[hive] class SparkGetFunctionsOperation(
     // get databases for schema pattern
     val schemaPattern = convertSchemaPattern(schemaName)
     val matchingDbs = catalog.listDatabases(schemaPattern)
-    val functionPattern = CLIServiceUtils.patternToRegex(functionName)
+    val functionPattern = functionName

Review Comment:
   Keep translating the JDBC function-name pattern before this call. `DatabaseMetaData.getFunctions` uses `%` and `_`, but `SessionCatalog.listFunctions` delegates to the `*`-based `StringUtils.filterPattern`; with the raw value, `getFunctions(..., "%")` now looks for a literal percent sign and returns no functions. Please bridge those pattern formats without restoring regex-metacharacter leakage, and add `%`/`_` coverage.



##########
sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/CLIServiceUtils.java:
##########
@@ -36,10 +36,14 @@ public class CLIServiceUtils {
   /**
    * Convert a SQL search pattern into an equivalent Java Regex.
    *
+   * Per JDBC spec, only '%' (match any substring) and '_' (match any single character) are
+   * wildcard characters. All other characters — including regex metacharacters like '*', '.',

Review Comment:
   Please replace both em dashes in this Javadoc with ASCII punctuation. Spark's source guidance prohibits non-ASCII typography in comments because it can trip style checks.



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


Re: [PR] [SPARK-57518][SQL][FOLLOWUP] List ThriftServer schemas via SupportsNamespaces instead of special-casing spark_catalog [spark]

Posted by "shrirangmhalgi (via GitHub)" <gi...@apache.org>.
shrirangmhalgi commented on code in PR #57468:
URL: https://github.com/apache/spark/pull/57468#discussion_r3642634618


##########
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 _ =>

Review Comment:
   nit: The `case _ =>` branch returns empty with no log. If a user's catalog doesn't implement `SupportsNamespaces`, they get 0 schemas with no indication why. A `logWarning` here would help diagnose "getSchemas returns nothing" bugs - e.g., `logWarning(s"Catalog ${resolvedCatalog.name()} does not implement SupportsNamespaces; returning empty schema list")`.



##########
sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkMetadataOperationSuite.scala:
##########
@@ -55,7 +55,7 @@ class SparkMetadataOperationSuite extends HiveThriftServer2TestBase {
         checkResult(metaData.getSchemas(null, pattern), dbs ++ dbDflts)
       }
 
-      Seq("db%", "db*") foreach { pattern =>
+      Seq("db%") foreach { pattern =>

Review Comment:
   (non-blocking): The removal of `"db*"` from this assertion documents that Hive-style glob wildcards no longer match on the V2 path. Since `isCatalogMetadataEnabled` defaults to `true`, this is a default-on behavior change for ThriftServer users — any client passing `*` instead of JDBC `%` will get 0 results. Would a negative assertion (e.g., `checkResult(metaData.getSchemas(null, "db*"), Seq.empty)`) make this more explicit for future readers?



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


Re: [PR] [SPARK-57518][SQL][FOLLOWUP] List ThriftServer schemas via SupportsNamespaces instead of special-casing spark_catalog [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #57468:
URL: https://github.com/apache/spark/pull/57468#discussion_r3642526097


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

Review Comment:
   @yadavay-amzn I think we can accept this for now, as users still have a backdoor (`isCatalogMetadataEnabled`) to go back to the old impl. 
   
   @cloud-fan for the long term, do we want to extend the V2 API to support predication pushdown? and the approach can also be either simple - just accept a string pattern like the current `ExternalCatalog`, or extendable - just like `SupportsPushDownFilters`



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


Re: [PR] [SPARK-57518][SQL][FOLLOWUP] List ThriftServer schemas via SupportsNamespaces instead of special-casing spark_catalog [spark]

Posted by "yadavay-amzn (via GitHub)" <gi...@apache.org>.
yadavay-amzn commented on code in PR #57468:
URL: https://github.com/apache/spark/pull/57468#discussion_r3660217291


##########
sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkMetadataOperationSuite.scala:
##########
@@ -804,6 +804,31 @@ class SparkMetadataOperationSuite extends HiveThriftServer2TestBase {
     }
   }
 
+  test("SPARK-57518: getSchemas for spark_catalog lists namespaces via SupportsNamespaces " +

Review Comment:
   Added a regression test with a custom `spark_catalog` override whose `listNamespaces()` differs from `SessionCatalog.listDatabases`. It asserts the override's namespaces show up and `default` doesn't, so it fails if the old special-case returns.



##########
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:
   You're right, that would double-count. Fixed: I only add the `global_temp` row when `listNamespaces()` didn't already return it, so there's at most one.



##########
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 _ =>

Review Comment:
   Added a `logWarning` there, so a catalog without `SupportsNamespaces` says so instead of silently returning nothing.



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


Re: [PR] [SPARK-57518][SQL][FOLLOWUP] List ThriftServer schemas via SupportsNamespaces instead of special-casing spark_catalog [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #57468:
URL: https://github.com/apache/spark/pull/57468#discussion_r3662535901


##########
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:
   In such a case, what will be returned if the user calls `SHOW TABLES IN global_temp`?



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


Re: [PR] [SPARK-57518][SQL][FOLLOWUP] List ThriftServer schemas via SupportsNamespaces instead of special-casing spark_catalog [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #57468:
URL: https://github.com/apache/spark/pull/57468#issuecomment-5519639214

   @yadavay-amzn do you have time to complete this before 4.3.0? otherwise I would suggest disabling `spark.sql.thriftServer.catalogMetadata.enabled` till 5.0.0


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


Re: [PR] [SPARK-57518][SQL][FOLLOWUP] List ThriftServer schemas via SupportsNamespaces instead of special-casing spark_catalog [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #57468:
URL: https://github.com/apache/spark/pull/57468#discussion_r3646898334


##########
sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkMetadataOperationSuite.scala:
##########
@@ -804,6 +804,31 @@ class SparkMetadataOperationSuite extends HiveThriftServer2TestBase {
     }
   }
 
+  test("SPARK-57518: getSchemas for spark_catalog lists namespaces via SupportsNamespaces " +

Review Comment:
   Please exercise a custom spark_catalog override here. This test uses the built-in V2SessionCatalog, so it returns the same schemas before and after the production change and cannot catch restoration of the removed SessionCatalog special case. A CatalogExtension whose listNamespaces result differs from SessionCatalog.listDatabases would make this a regression test for the behavior the PR fixes.



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


Re: [PR] [SPARK-57518][SQL][FOLLOWUP] List ThriftServer schemas via SupportsNamespaces instead of special-casing spark_catalog [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #57468:
URL: https://github.com/apache/spark/pull/57468#discussion_r3642526097


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

Review Comment:
   @yadavay-amzn I think we can accept this for now, as users still have a backdoor (`isCatalogMetadataEnabled`) to go back to the old impl. 
   
   @cloud-fan for the long term, do we want to extend the V2 API to support predication pushdown on listing ns/table/func/col? and the approach can also be either simple - just accept a string pattern like the current `ExternalCatalog`, or extendable - just like `SupportsPushDownFilters`



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


Re: [PR] [SPARK-57518][SQL][FOLLOWUP] List ThriftServer schemas via SupportsNamespaces instead of special-casing spark_catalog [spark]

Posted by "yadavay-amzn (via GitHub)" <gi...@apache.org>.
yadavay-amzn commented on PR #57468:
URL: https://github.com/apache/spark/pull/57468#issuecomment-5065356008

   @pan3793 here's the follow-up we discussed. It lists schemas uniformly via the current catalog's `SupportsNamespaces` and keeps `global_temp` as a session-catalog special case. On the perf point you raised: `listNamespaces()` has no pattern argument, so the schema pattern is filtered client-side; I called that out under "Performance consideration" in the description. Happy to hear how you'd like to handle pushdown, or whether a separate DSv2 API change is the better place for 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


Re: [PR] [SPARK-57518][SQL][FOLLOWUP] List ThriftServer schemas via SupportsNamespaces instead of special-casing spark_catalog [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
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: 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


Re: [PR] [SPARK-57518][SQL][FOLLOWUP] List ThriftServer schemas via SupportsNamespaces instead of special-casing spark_catalog [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #57468:
URL: https://github.com/apache/spark/pull/57468#discussion_r3675495403


##########
sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkMetadataOperationSuite.scala:
##########
@@ -55,7 +56,10 @@ class SparkMetadataOperationSuite extends HiveThriftServer2TestBase {
         checkResult(metaData.getSchemas(null, pattern), dbs ++ dbDflts)
       }
 
-      Seq("db%", "db*") foreach { pattern =>
+      // Note: "db*" was removed because `*` is not a valid JDBC wildcard character
+      // (only `%` and `_` are); on the DSv2 SupportsNamespaces path it is treated as a

Review Comment:
   JDBC pattern matching should treat characters other than `%` and `_` literally, but `patternToRegex` leaves Java regex metacharacters unescaped. As a result, `db*` matches schemas named `db` or `dbb`, while a bare `*` throws a pattern error; the current `db1`/`db2` fixture only hides this. Please quote regex metacharacters in `patternToRegex` while preserving the `%`/`_` translations, and add `db`/`dbb` counterexamples here.



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