You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "j1wonpark (via GitHub)" <gi...@apache.org> on 2026/08/10 05:42:34 UTC

[PR] [SPARK-58684][PYTHON] Make get_sqlstate fall back to the main error class's sqlState [spark]

j1wonpark opened a new pull request, #57887:
URL: https://github.com/apache/spark/pull/57887

   ### What changes were proposed in this pull request?
   
   `ErrorClassesReader.get_sqlstate` returns `None` for a sub-class that does not declare its own `sqlState`, even when its main class declares one. This makes it fall back to the main class, matching `get_breaking_change_info` in the same file and `ErrorClassesJsonReader.getSqlState` on the JVM side.
   
   Split out of #57831; the two are unrelated, as `python/pyspark/errors/error-conditions.json` is a separate file and does not contain the condition that PR is about.
   
   ### Why are the changes needed?
   
   `getSqlState()` is public API on `PySparkException`. `NEAREST_BY_JOIN` declares `42604`, but:
   
   ```python
   >>> from pyspark.errors import PySparkRuntimeError
   >>> e = PySparkRuntimeError(
   ...     errorClass="NEAREST_BY_JOIN.UNSUPPORTED_MODE",
   ...     messageParameters={"mode": "invalid", "supported": "nearest"},
   ... )
   >>> print(e.getSqlState())
   None
   ```
   
   The JVM reader falls back to the main class here, so the two sides report different SQLSTATEs for the same condition.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `getSqlState()` returns the main class's SQLSTATE for a sub-class without its own, instead of `None` — `NEAREST_BY_JOIN.*` goes from `None` to `42604`, the only condition affected today. Where neither level declares one, it still returns `None`.
   
   ### How was this patch tested?
   
   Added a case to `test_sqlstate` pinning `NEAREST_BY_JOIN.UNSUPPORTED_MODE` to `42604`, written test-first and confirmed failing before the fix. All 6 tests in `pyspark.errors.tests.test_errors` pass.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (claude-fable-5, claude-opus-5)
   


-- 
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-58684][PYTHON] Make PySpark error sub-conditions inherit the parent condition error state [spark]

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

   Renamed, thanks. Also updated the description to use the same terminology.


-- 
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-58684][PYTHON] Make get_sqlstate fall back to the main error class's sqlState [spark]

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

   Thank you @j1wonpark!


-- 
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-58684][PYTHON] Make PySpark error sub-conditions inherit the parent condition error state [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 closed pull request #57887: [SPARK-58684][PYTHON] Make PySpark error sub-conditions inherit the parent condition error state
URL: https://github.com/apache/spark/pull/57887


-- 
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-58684][PYTHON] Make PySpark error sub-conditions inherit the parent condition error state [spark]

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

   so this one is a standalone bugfix, should land all active branches?


-- 
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-58684][PYTHON] Make get_sqlstate fall back to the main error class's sqlState [spark]

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


##########
python/pyspark/errors/utils.py:
##########
@@ -98,20 +98,22 @@ def __init__(self) -> None:
     def get_sqlstate(self, errorClass: Optional[str]) -> Optional[str]:
         """
         Returns the SQL state for the given error class.
+
+        A sub-class with its own sqlState overrides the main class's; a sub-class
+        without one inherits the main class's.

Review Comment:
   Correct, inheritance is the only intent. Dropped the override branch and reworded the docstring. The lookup is `split(".")[0]` only now, same as `ErrorClassesJsonReader.getSqlState` on the JVM side.



##########
python/pyspark/errors/tests/test_errors.py:
##########
@@ -118,12 +118,20 @@ def test_sqlstate(self):
         error = PySparkRuntimeError(errorClass="APPLICATION_NAME_NOT_SET", messageParameters={})
         self.assertIsNone(error.getSqlState())
 
+        # Neither the sub-class nor the main class declares a sqlState.
         error = PySparkRuntimeError(
             errorClass="SESSION_MUTATION_IN_DECLARATIVE_PIPELINE.SET_RUNTIME_CONF",
             messageParameters={"method": "set"},
         )
         self.assertIsNone(error.getSqlState())
 
+        # A sub-class without its own sqlState inherits the main class's.
+        error = PySparkRuntimeError(
+            errorClass="NEAREST_BY_JOIN.UNSUPPORTED_MODE",

Review Comment:
   You're right, it did not. `test_sqlstate_is_taken_from_the_main_class` pins it now: the sub-class declares `08003` under a main class of `42604`, and the lookup returns `42604`. With the override branch gone the sub-class entry is never read, so it cannot rot.



-- 
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-58684][PYTHON] Make PySpark error sub-conditions inherit the parent condition error state [spark]

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

   **Merge Summary:**
   - merged into master https://github.com/apache/spark/commit/59a50f8c68c6ab1168a6e508a94d13959e8264aa
   - merged into branch-4.x https://github.com/apache/spark/commit/1e4c6b96905b5f09d978c511f8aabeb5cdf6172e
   - merged into branch-4.3 https://github.com/apache/spark/commit/e441259b27fb7991bdce3a9eb7ef096ce1593583
   - merged into branch-4.2 https://github.com/apache/spark/commit/2bd3a470c3425604a4727fcd4203bebec674463b
   
   *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-58684][PYTHON] Make get_sqlstate fall back to the main error class's sqlState [spark]

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


##########
python/pyspark/errors/utils.py:
##########
@@ -98,20 +98,22 @@ def __init__(self) -> None:
     def get_sqlstate(self, errorClass: Optional[str]) -> Optional[str]:
         """
         Returns the SQL state for the given error class.
+
+        A sub-class with its own sqlState overrides the main class's; a sub-class
+        without one inherits the main class's.

Review Comment:
   If the intention is to have sub-conditions inherit the parent condition error state, that's one thing. But allowing a sub-condition to _override_ the parent error state is another thing.
   
   I think in this PR your intention is just to do the former, correct? If so, I would update this docstring and the behavior below accordingly.



##########
python/pyspark/errors/tests/test_errors.py:
##########
@@ -118,12 +118,20 @@ def test_sqlstate(self):
         error = PySparkRuntimeError(errorClass="APPLICATION_NAME_NOT_SET", messageParameters={})
         self.assertIsNone(error.getSqlState())
 
+        # Neither the sub-class nor the main class declares a sqlState.
         error = PySparkRuntimeError(
             errorClass="SESSION_MUTATION_IN_DECLARATIVE_PIPELINE.SET_RUNTIME_CONF",
             messageParameters={"method": "set"},
         )
         self.assertIsNone(error.getSqlState())
 
+        # A sub-class without its own sqlState inherits the main class's.
+        error = PySparkRuntimeError(
+            errorClass="NEAREST_BY_JOIN.UNSUPPORTED_MODE",

Review Comment:
   Does this test ensure that the sub-condition does _not_ have an error state? Because while that may be true now, it may change in the future and silently invalidate the purpose of this test



##########
python/pyspark/errors/tests/test_errors.py:
##########
@@ -118,12 +118,20 @@ def test_sqlstate(self):
         error = PySparkRuntimeError(errorClass="APPLICATION_NAME_NOT_SET", messageParameters={})
         self.assertIsNone(error.getSqlState())
 
+        # Neither the sub-class nor the main class declares a sqlState.
         error = PySparkRuntimeError(
             errorClass="SESSION_MUTATION_IN_DECLARATIVE_PIPELINE.SET_RUNTIME_CONF",
             messageParameters={"method": "set"},
         )
         self.assertIsNone(error.getSqlState())
 
+        # A sub-class without its own sqlState inherits the main class's.
+        error = PySparkRuntimeError(
+            errorClass="NEAREST_BY_JOIN.UNSUPPORTED_MODE",

Review Comment:
   Does this test ensure that the sub-condition does _not_ have an error state? Because while that may be true now, it may change in the future and silently invalidate the purpose of this test.



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