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/06/20 01:46:21 UTC

[PR] [SPARK-57518][SQL] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware [spark]

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

   ### What changes were proposed in this pull request?
   
   Route ThriftServer JDBC metadata operations (getCatalogs, getSchemas, getTables, getColumns) through CatalogManager so they honor DataSource V2 catalogs and the default catalog. Populate TABLE_CAT with the real catalog name. Introduce a new conf `spark.sql.thriftServer.catalogMetadata.enabled` (default true) with legacy fallback when disabled.
   
   ### Why are the changes needed?
   
   With `spark.sql.catalog.*` and `spark.sql.defaultCatalog` set, JDBC/BI clients get inconsistent metadata because the metadata operations used the V1 SessionCatalog directly, ignoring any configured DSv2 catalogs.
   
   ### Design notes
   
   (a) A null `catalogName` resolves to the CURRENT catalog (consistent with Spark's own unspecified-to-current resolution and with Trino/Snowflake behavior), not all catalogs.
   
   (b) getCatalogs returns CatalogManager.listCatalogs() (including spark_catalog, sorted alphabetically).
   
   (c) TABLE_CAT was previously empty or null -- now populated with the actual catalog name. The conf defaults to ON with an escape hatch for clients that relied on parsing empty TABLE_CAT.
   
   (d) KNOWN LIMITATION: listCatalogs() returns only ALREADY-LOADED catalogs, so catalogs that are configured but never accessed will not be listed. This is documented; we do not eagerly load catalogs.
   
   (e) V2-specific metadata authorization is deferred to a follow-up. Existing Hive auth hooks are unchanged and getCatalogs/getSchemas already pass null priv objects.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. TABLE_CAT now reflects the catalog name (gated by the new conf). New conf: `spark.sql.thriftServer.catalogMetadata.enabled`.
   
   ### How was this patch tested?
   
   SparkMetadataOperationSuite covers: default spark_catalog path, configured in-memory DSv2 catalog path, and conf-disabled legacy path (getCatalogs, getSchemas, getTables, getColumns).
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Yes.
   


-- 
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] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware [spark]

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

   **Merge Summary:**
   - merged into master https://github.com/apache/spark/commit/2274217b217e699b552c9d5d398fa1405260215b
   - merged into branch-4.x https://github.com/apache/spark/commit/a36444b4e5157d9ad1cff0365c72c7fded062c3d
   
   *Posted by `merge_spark_pr.py`*


-- 
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] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware [spark]

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


##########
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetSchemasOperation.scala:
##########
@@ -71,15 +72,51 @@ private[hive] class SparkGetSchemasOperation(
 
     try {
       val schemaPattern = convertSchemaPattern(schemaName)
-      catalog.listDatabases(schemaPattern).foreach { dbName =>
-        rowSet.addRow(Array[AnyRef](dbName, DEFAULT_HIVE_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, DEFAULT_HIVE_CATALOG))
+      if (isCatalogMetadataEnabled) {
+        // The JDBC catalogName parameter is intentionally not used for filtering;
+        // resolution always uses the current catalog (SPARK-57518; per-catalog
+        // filtering deferred).
+        val resolvedCatalog = catalogManager.currentCatalog
+        val catalogNameValue = resolvedCatalog.name()
+        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))
+          }
+        } else {
+          resolvedCatalog match {
+            case nsCatalog: SupportsNamespaces =>
+              val databasePattern = Pattern.compile(
+                CLIServiceUtils.patternToRegex(schemaName))
+              nsCatalog.listNamespaces().foreach { ns =>

Review Comment:
   Added a known-limitation note to the conf's doc string: when the current catalog is a DSv2 catalog and this conf is enabled, getSchemas lists the DSv2 catalog's namespaces while getTables/getColumns still enumerate spark_catalog objects, until the getTables/getColumns DSv2 routing follow-up lands. The sessionCatalogTableCat guard (with the negative test) keeps TABLE_CAT correctly labeled in the meantime.



-- 
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] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware [spark]

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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -2045,6 +2045,17 @@ object SQLConf {
     .intConf
     .createWithDefault(200)
 
+  val THRIFTSERVER_CATALOG_METADATA_ENABLED =
+    buildConf("spark.sql.thriftServer.catalogMetadata.enabled")
+      .doc("When true, JDBC metadata operations (getCatalogs, getSchemas, getTables, " +
+        "getColumns) are DataSource V2 catalog-aware: getCatalogs returns all loaded catalogs, " +
+        "and TABLE_CAT is populated with the real catalog name. When false, the legacy behavior " +
+        "is preserved (empty TABLE_CAT and getCatalogs returns no rows).")
+      .version("5.0.0")

Review Comment:
   Changed to .version("4.3.0") - agreed, this is a backportable, conf-gated feature so it should ship in branch-4.x rather than master-only.



##########
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetSchemasOperation.scala:
##########
@@ -71,15 +72,51 @@ private[hive] class SparkGetSchemasOperation(
 
     try {
       val schemaPattern = convertSchemaPattern(schemaName)
-      catalog.listDatabases(schemaPattern).foreach { dbName =>
-        rowSet.addRow(Array[AnyRef](dbName, DEFAULT_HIVE_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, DEFAULT_HIVE_CATALOG))
+      if (isCatalogMetadataEnabled) {
+        // The JDBC catalogName parameter is intentionally not used for filtering;
+        // resolution always uses the current catalog (SPARK-57518; per-catalog
+        // filtering deferred).
+        val resolvedCatalog = catalogManager.currentCatalog
+        val catalogNameValue = resolvedCatalog.name()
+        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))
+          }
+        } else {
+          resolvedCatalog match {
+            case nsCatalog: SupportsNamespaces =>
+              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

Review Comment:
   Fixed - replaced the em-dash with ASCII '--' (applied your suggestion), and confirmed no other non-ASCII in the changed lines.



-- 
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] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware [spark]

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


##########
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetSchemasOperation.scala:
##########
@@ -71,15 +72,51 @@ private[hive] class SparkGetSchemasOperation(
 
     try {
       val schemaPattern = convertSchemaPattern(schemaName)
-      catalog.listDatabases(schemaPattern).foreach { dbName =>
-        rowSet.addRow(Array[AnyRef](dbName, DEFAULT_HIVE_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, DEFAULT_HIVE_CATALOG))
+      if (isCatalogMetadataEnabled) {
+        // The JDBC catalogName parameter is intentionally not used for filtering;
+        // resolution always uses the current catalog (SPARK-57518; per-catalog
+        // filtering deferred).
+        val resolvedCatalog = catalogManager.currentCatalog
+        val catalogNameValue = resolvedCatalog.name()
+        if (catalogNameValue == CatalogManager.SESSION_CATALOG_NAME) {
+          // For spark_catalog, use the V1 SessionCatalog directly (transparent delegation)

Review Comment:
   You're right, assuming delegation isn't safe. Since the default `V2SessionCatalog` also implements `SupportsNamespaces`, we can call `listNamespaces()` on the current catalog directly in all cases and drop the `spark_catalog` special-case, which also correctly reflects an overridden catalog's own namespaces. The one piece to keep separate is the global temp view database, since it isn't a real namespace. I can put up a follow-up PR for that. Does that approach sound right to you?
   



-- 
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] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware [spark]

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

   Could you please take a look at this when you get the chance @yaooqinn @pan3793 @cloud-fan  


-- 
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] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware [spark]

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


##########
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetSchemasOperation.scala:
##########
@@ -71,15 +72,51 @@ private[hive] class SparkGetSchemasOperation(
 
     try {
       val schemaPattern = convertSchemaPattern(schemaName)
-      catalog.listDatabases(schemaPattern).foreach { dbName =>
-        rowSet.addRow(Array[AnyRef](dbName, DEFAULT_HIVE_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, DEFAULT_HIVE_CATALOG))
+      if (isCatalogMetadataEnabled) {
+        // The JDBC catalogName parameter is intentionally not used for filtering;
+        // resolution always uses the current catalog (SPARK-57518; per-catalog
+        // filtering deferred).
+        val resolvedCatalog = catalogManager.currentCatalog
+        val catalogNameValue = resolvedCatalog.name()
+        if (catalogNameValue == CatalogManager.SESSION_CATALOG_NAME) {
+          // For spark_catalog, use the V1 SessionCatalog directly (transparent delegation)

Review Comment:
   we should not assume that the impl delegates its namespace listing to the built-in session catalog. 
   
   the default `V2SessionCatalog` also impl `SupportsNamespaces`, why not call it directly?



-- 
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] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #56627: [SPARK-57518][SQL] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware
URL: https://github.com/apache/spark/pull/56627


-- 
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] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware [spark]

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


##########
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetSchemasOperation.scala:
##########
@@ -71,15 +72,51 @@ private[hive] class SparkGetSchemasOperation(
 
     try {
       val schemaPattern = convertSchemaPattern(schemaName)
-      catalog.listDatabases(schemaPattern).foreach { dbName =>
-        rowSet.addRow(Array[AnyRef](dbName, DEFAULT_HIVE_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, DEFAULT_HIVE_CATALOG))
+      if (isCatalogMetadataEnabled) {
+        // The JDBC catalogName parameter is intentionally not used for filtering;
+        // resolution always uses the current catalog (SPARK-57518; per-catalog
+        // filtering deferred).
+        val resolvedCatalog = catalogManager.currentCatalog
+        val catalogNameValue = resolvedCatalog.name()
+        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))
+          }
+        } else {
+          resolvedCatalog match {
+            case nsCatalog: SupportsNamespaces =>
+              val databasePattern = Pattern.compile(
+                CLIServiceUtils.patternToRegex(schemaName))
+              nsCatalog.listNamespaces().foreach { ns =>

Review Comment:
   Non-blocking, and I see this is an acknowledged follow-up (design note f) — flagging for visibility. With a DSv2 catalog as the current catalog and this conf on, `getSchemas` here returns the DSv2 catalog's namespaces, but `getTables`/`getColumns` still enumerate `spark_catalog`'s objects (with empty/null `TABLE_CAT`, via `sessionCatalogTableCat`). A JDBC/BI client that drills schema → tables then sees namespaces from one catalog and tables from another for the same session. The `sessionCatalogTableCat` guard correctly prevents mislabeling (nicely pinned by the negative test), so this isn't a bug — just worth a line in the conf `doc(...)` / known-limitations so integrators aren't surprised until the getTables/getColumns DSv2 routing follow-up lands.



##########
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetSchemasOperation.scala:
##########
@@ -71,15 +72,51 @@ private[hive] class SparkGetSchemasOperation(
 
     try {
       val schemaPattern = convertSchemaPattern(schemaName)
-      catalog.listDatabases(schemaPattern).foreach { dbName =>
-        rowSet.addRow(Array[AnyRef](dbName, DEFAULT_HIVE_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, DEFAULT_HIVE_CATALOG))
+      if (isCatalogMetadataEnabled) {
+        // The JDBC catalogName parameter is intentionally not used for filtering;
+        // resolution always uses the current catalog (SPARK-57518; per-catalog
+        // filtering deferred).
+        val resolvedCatalog = catalogManager.currentCatalog
+        val catalogNameValue = resolvedCatalog.name()
+        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))
+          }
+        } else {
+          resolvedCatalog match {
+            case nsCatalog: SupportsNamespaces =>
+              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

Review Comment:
   Nit: this comment uses a non-ASCII em-dash; the repo convention is ASCII-only in comments.
   ```suggestion
                 // Catalog doesn't support namespaces -- return empty
   ```



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -2045,6 +2045,17 @@ object SQLConf {
     .intConf
     .createWithDefault(200)
 
+  val THRIFTSERVER_CATALOG_METADATA_ENABLED =
+    buildConf("spark.sql.thriftServer.catalogMetadata.enabled")
+      .doc("When true, JDBC metadata operations (getCatalogs, getSchemas, getTables, " +
+        "getColumns) are DataSource V2 catalog-aware: getCatalogs returns all loaded catalogs, " +
+        "and TABLE_CAT is populated with the real catalog name. When false, the legacy behavior " +
+        "is preserved (empty TABLE_CAT and getCatalogs returns no rows).")
+      .version("5.0.0")

Review Comment:
   Per Spark's branch policy, a normally-backported, conf-gated feature with no binary-incompatibility ships first in the next open feature release branch (`branch-4.x`, currently 4.3.0), so `.version("4.3.0")` is usually the expected value rather than master's `5.0.0`. If this is intentionally master-only, feel free to keep 5.0.0. (Heads-up: one other conf already on master also uses 5.0.0, so this may be fine — just confirming intent.)



-- 
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] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware [spark]

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


##########
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetSchemasOperation.scala:
##########
@@ -71,15 +72,51 @@ private[hive] class SparkGetSchemasOperation(
 
     try {
       val schemaPattern = convertSchemaPattern(schemaName)
-      catalog.listDatabases(schemaPattern).foreach { dbName =>
-        rowSet.addRow(Array[AnyRef](dbName, DEFAULT_HIVE_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, DEFAULT_HIVE_CATALOG))
+      if (isCatalogMetadataEnabled) {
+        // The JDBC catalogName parameter is intentionally not used for filtering;
+        // resolution always uses the current catalog (SPARK-57518; per-catalog
+        // filtering deferred).
+        val resolvedCatalog = catalogManager.currentCatalog
+        val catalogNameValue = resolvedCatalog.name()
+        if (catalogNameValue == CatalogManager.SESSION_CATALOG_NAME) {
+          // For spark_catalog, use the V1 SessionCatalog directly (transparent delegation)

Review Comment:
   yeah, global temp view db is a special case, please open a PR to impl the proposal and see if CI is happy. another thing I spotted: the DSv2 API does not allow passing a filter on listing ns/db/table/view, this might cause perf regression. anyway, let's discuss those details in your new PR



-- 
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] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware [spark]

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


##########
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetSchemasOperation.scala:
##########
@@ -71,15 +72,51 @@ private[hive] class SparkGetSchemasOperation(
 
     try {
       val schemaPattern = convertSchemaPattern(schemaName)
-      catalog.listDatabases(schemaPattern).foreach { dbName =>
-        rowSet.addRow(Array[AnyRef](dbName, DEFAULT_HIVE_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, DEFAULT_HIVE_CATALOG))
+      if (isCatalogMetadataEnabled) {
+        // The JDBC catalogName parameter is intentionally not used for filtering;
+        // resolution always uses the current catalog (SPARK-57518; per-catalog
+        // filtering deferred).
+        val resolvedCatalog = catalogManager.currentCatalog
+        val catalogNameValue = resolvedCatalog.name()
+        if (catalogNameValue == CatalogManager.SESSION_CATALOG_NAME) {
+          // For spark_catalog, use the V1 SessionCatalog directly (transparent delegation)

Review Comment:
   what if the user overrides the `spark_catalog` impl? a typical use case is:
   
   ```
   spark.sql.catalog.spark_catalog=org.apache.iceberg.spark.SparkSessionCatalog
   ```



-- 
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] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware [spark]

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

   thanks, merging to master/4.x


-- 
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] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware [spark]

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

   Thanks for reviewing and merging @cloud-fan !
   A small bookkeeping nit (please ignore if not needed), I noticed that PR isn't approved. Will defer to you here but wanted to bring it your attention in case you missed 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] Make ThriftServer JDBC metadata operations DataSource V2 catalog-aware [spark]

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


##########
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkGetSchemasOperation.scala:
##########
@@ -71,15 +72,51 @@ private[hive] class SparkGetSchemasOperation(
 
     try {
       val schemaPattern = convertSchemaPattern(schemaName)
-      catalog.listDatabases(schemaPattern).foreach { dbName =>
-        rowSet.addRow(Array[AnyRef](dbName, DEFAULT_HIVE_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, DEFAULT_HIVE_CATALOG))
+      if (isCatalogMetadataEnabled) {
+        // The JDBC catalogName parameter is intentionally not used for filtering;
+        // resolution always uses the current catalog (SPARK-57518; per-catalog
+        // filtering deferred).
+        val resolvedCatalog = catalogManager.currentCatalog
+        val catalogNameValue = resolvedCatalog.name()
+        if (catalogNameValue == CatalogManager.SESSION_CATALOG_NAME) {
+          // For spark_catalog, use the V1 SessionCatalog directly (transparent delegation)

Review Comment:
   Thanks for raising this. With an overridden `spark_catalog` (e.g. Iceberg's `SparkSessionCatalog`), `catalogManager.currentCatalog.name()` is still `spark_catalog` (`SESSION_CATALOG_NAME`), so this branch is taken and it lists via the V1 `SessionCatalog` rather than the override's `listNamespaces()`. I think that's the intended behavior here: Iceberg's `SparkSessionCatalog` delegates its namespace listing to the built-in session catalog (`listNamespaces()` just calls `getSessionCatalog().listNamespaces()`), so the databases it exposes are the same ones the V1 catalog returns. Where it could differ is a custom `spark_catalog` override that lists its own namespaces instead of delegating. Do you think we should handle this in a follow-up change?
   



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