You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "cloud-fan (via GitHub)" <gi...@apache.org> on 2026/02/10 17:06:02 UTC

[PR] [SPARK-55024][SQL][FOLLOWUP] Delay namespace length check to v1 identifier creation [spark]

cloud-fan opened a new pull request, #54247:
URL: https://github.com/apache/spark/pull/54247

   ### What changes were proposed in this pull request?
   
   This is a followup to #53788 which moved the namespace length check from individual command handlers to the `CatalogAndIdentifier` extractor. That approach is too aggressive: users can extend the session catalog via `CatalogExtension` and support multi-part namespaces through v2 APIs. The check should only happen when we actually create v1 identifiers like `TableIdentifier`, not at the shared name-resolution layer.
   
   ### Changes
   
   - **Remove the namespace check from `CatalogAndIdentifier.unapply`** so it remains a pure name-resolution mechanism, preserving `CatalogExtension` flexibility.
   - **Tighten `CatalogV2Implicits.IdentifierHelper.asTableIdentifier` and `asFunctionIdentifier`** to require exactly one namespace part and throw `REQUIRES_SINGLE_PART_NAMESPACE` (instead of the less precise `IDENTIFIER_TOO_MANY_NAME_PARTS`). This centralizes the validation.
   - **Remove the now-redundant `V2SessionCatalog.TableIdentifierHelper`** and use the unified `CatalogV2Implicits` conversion everywhere.
   - **Simplify `ResolveSessionCatalog` extractors** (`ResolvedV1Identifier`, `ResolvedIdentifierInSessionCatalog`, `ResolvedViewIdentifier`) to delegate to `ident.asTableIdentifier`.
   - **Fix `SparkSqlParser` temp view creation** to check name length before calling `asTableIdentifier`, so the user always sees `notAllowedToAddDBPrefixForTempViewError` instead of a generic error.
   
   ### Why are the changes needed?
   
   `CatalogExtension` allows users to extend the built-in session catalog and potentially support multi-part namespaces for v2 operations. The early check in `CatalogAndIdentifier` would block such extensions. The namespace length should only be validated when we actually need to create v1 identifiers (e.g. `TableIdentifier`), which inherently require a single-part namespace.
   
   Additionally, this PR unifies the scattered namespace validation into a single point (`CatalogV2Implicits.IdentifierHelper`), reducing code duplication and ensuring consistent `REQUIRES_SINGLE_PART_NAMESPACE` errors.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. Multi-part namespace identifiers now flow through `CatalogAndIdentifier` without error, allowing `CatalogExtension` implementations to handle them. The error is only thrown when the session catalog actually needs to convert to a v1 identifier.
   
   ### How was this patch tested?
   
   Existing tests updated:
   - `LookupCatalogSuite` — removed the early-rejection test, added multi-part namespace cases back.
   - `V2SessionCatalogSuite` — updated to expect `REQUIRES_SINGLE_PART_NAMESPACE`.
   - `DataSourceV2SQLSuiteV1Filter` and `DataSourceV2FunctionSuite` — all 313 tests pass.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Yes.
   
   
   Made with [Cursor](https://cursor.com)


-- 
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-55024][SQL][FOLLOWUP] Delay namespace length check to v1 identifier creation [spark]

Posted by "szehon-ho (via GitHub)" <gi...@apache.org>.
szehon-ho commented on code in PR #54247:
URL: https://github.com/apache/spark/pull/54247#discussion_r2791679687


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/CatalogV2Implicits.scala:
##########
@@ -166,9 +166,10 @@ private[sql] object CatalogV2Implicits {
     def asMultipartIdentifier: Seq[String] = (ident.namespace :+ ident.name).toImmutableArraySeq
 
     def asTableIdentifier: TableIdentifier = ident.namespace match {
-      case ns if ns.isEmpty => TableIdentifier(ident.name)

Review Comment:
   curious here, is it necessary to remove these if ns is not empty?  I see that asTableIdentifierOpt still handles the empty ns case.  
   
   I assume in V1SessionCatalog case, the namespace is never empty, but just checking if its necessary to remove, in case some v2 connector is using the method



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalogSuite.scala:
##########
@@ -1162,8 +1162,8 @@ class V2SessionCatalogNamespaceSuite extends V2SessionCatalogBaseSuite {
     val testIdent: IdentifierHelper = Identifier.of(Array("a", "b"), "c")
     checkError(
       exception = intercept[AnalysisException](testIdent.asTableIdentifier),
-      condition = "IDENTIFIER_TOO_MANY_NAME_PARTS",
-      parameters = Map("identifier" -> "`a`.`b`.`c`", "limit" -> "2")
+      condition = "REQUIRES_SINGLE_PART_NAMESPACE",

Review Comment:
   just opinion that previously having the identifier was a bit easier to debug.  I wonder if we can extend the error message to have a version with identifier?



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala:
##########
@@ -698,12 +698,12 @@ class SparkSqlAstBuilder extends AstBuilder {
       }
 
       withIdentClause(ctx.identifierReference(), Seq(qPlan), (ident, otherPlans) => {
-        val tableIdentifier = ident.asTableIdentifier
-        if (tableIdentifier.database.isDefined) {
+        if (ident.length > 1) {

Review Comment:
   is this case covered by some test?  (its easy to understand though, so not blocking)



-- 
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-55024][SQL][FOLLOWUP] Delay namespace length check to v1 identifier creation [spark]

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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/CatalogV2Implicits.scala:
##########
@@ -166,9 +166,10 @@ private[sql] object CatalogV2Implicits {
     def asMultipartIdentifier: Seq[String] = (ident.namespace :+ ident.name).toImmutableArraySeq
 
     def asTableIdentifier: TableIdentifier = ident.namespace match {
-      case ns if ns.isEmpty => TableIdentifier(ident.name)

Review Comment:
   It should never be empty, we have stricter check in other places before: https://github.com/apache/spark/pull/54247/changes#diff-415c3b78d7558933c759da01218075e011c45c4d0fb5ff3fe522f24d6e4b8e20L730



-- 
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-55024][SQL][FOLLOWUP] Delay namespace length check to v1 identifier creation [spark]

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


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala:
##########
@@ -698,12 +698,12 @@ class SparkSqlAstBuilder extends AstBuilder {
       }
 
       withIdentClause(ctx.identifierReference(), Seq(qPlan), (ident, otherPlans) => {
-        val tableIdentifier = ident.asTableIdentifier
-        if (tableIdentifier.database.isDefined) {
+        if (ident.length > 1) {

Review Comment:
   this is just a refactor here. The previous behavior is not changed, and I think it should have been tested before.



-- 
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-55024][SQL][FOLLOWUP] Delay namespace length check to v1 identifier creation [spark]

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


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalogSuite.scala:
##########
@@ -1162,8 +1162,8 @@ class V2SessionCatalogNamespaceSuite extends V2SessionCatalogBaseSuite {
     val testIdent: IdentifierHelper = Identifier.of(Array("a", "b"), "c")
     checkError(
       exception = intercept[AnalysisException](testIdent.asTableIdentifier),
-      condition = "IDENTIFIER_TOO_MANY_NAME_PARTS",
-      parameters = Map("identifier" -> "`a`.`b`.`c`", "limit" -> "2")
+      condition = "REQUIRES_SINGLE_PART_NAMESPACE",

Review Comment:
   good point, working on 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-55024][SQL][FOLLOWUP] Delay namespace length check to v1 identifier creation [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #54247: [SPARK-55024][SQL][FOLLOWUP] Delay namespace length check to v1 identifier creation
URL: https://github.com/apache/spark/pull/54247


-- 
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-55024][SQL][FOLLOWUP] Delay namespace length check to v1 identifier creation [spark]

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

   Could you double-check the following two failures, @cloud-fan ?
   
   <img width="578" height="518" alt="Screenshot 2026-02-10 at 12 18 51 PM" src="https://github.com/user-attachments/assets/cd1654f3-6aea-4266-b7fd-c5cea2ed6031" />
   


-- 
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-55024][SQL][FOLLOWUP] Delay namespace length check to v1 identifier creation [spark]

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

   thanks for the review, merging to master!


-- 
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-55024][SQL][FOLLOWUP] Delay namespace length check to v1 identifier creation [spark]

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


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala:
##########
@@ -698,12 +698,12 @@ class SparkSqlAstBuilder extends AstBuilder {
       }
 
       withIdentClause(ctx.identifierReference(), Seq(qPlan), (ident, otherPlans) => {
-        val tableIdentifier = ident.asTableIdentifier
-        if (tableIdentifier.database.isDefined) {
+        if (ident.length > 1) {

Review Comment:
   yes: https://github.com/apache/spark/pull/54247/changes#diff-1fd98ab15bfc9b8068b37cc5cfbc3376ee63ca2d18600a502db3012d24915424R718



-- 
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-55024][SQL][FOLLOWUP] Delay namespace length check to v1 identifier creation [spark]

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

   cc @manuzhang @szehon-ho @gengliangwang 


-- 
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-55024][SQL][FOLLOWUP] Delay namespace length check to v1 identifier creation [spark]

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


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala:
##########
@@ -698,12 +698,12 @@ class SparkSqlAstBuilder extends AstBuilder {
       }
 
       withIdentClause(ctx.identifierReference(), Seq(qPlan), (ident, otherPlans) => {
-        val tableIdentifier = ident.asTableIdentifier
-        if (tableIdentifier.database.isDefined) {
+        if (ident.length > 1) {

Review Comment:
   this is just a refactor here. The previous behavior is not changed, and I think it should have been tested before.



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