Skip to content

[SPARK-58684][PYTHON] Make PySpark error sub-conditions inherit the parent condition error state - #57887

Open
j1wonpark wants to merge 2 commits into
apache:masterfrom
j1wonpark:pyspark-get-sqlstate-fallback
Open

[SPARK-58684][PYTHON] Make PySpark error sub-conditions inherit the parent condition error state#57887
j1wonpark wants to merge 2 commits into
apache:masterfrom
j1wonpark:pyspark-get-sqlstate-fallback

Conversation

@j1wonpark

@j1wonpark j1wonpark commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

ErrorClassesReader.get_sqlstate looks the error state up under the sub-condition, so a sub-condition reports None even when its condition declares one. This makes the lookup resolve on the condition only, matching 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:

>>> 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 resolves on the condition here, so the two sides report different error states for the same condition.

Does this PR introduce any user-facing change?

Yes. getSqlState() returns the condition's error state for a sub-condition instead of None: NEAREST_BY_JOIN.* goes from None to 42604, the only condition affected today. Where the condition itself declares no error state, 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. Added test_sqlstate_is_taken_from_the_main_class covering a sub-condition that declares a different error state, an unknown sub-condition name, and an unknown condition. All 7 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)

…lass's sqlState

get_sqlstate reads a sub-class level sqlState (SPARK-54532) but returns
None when the sub-class does not declare one, even if the main class
does: NEAREST_BY_JOIN.UNSUPPORTED_MODE reported no SQLSTATE despite
NEAREST_BY_JOIN declaring 42604. get_breaking_change_info already falls
back to the main class for the same shape.

Make the resolution match the JVM framework: a sub-class sqlState
overrides the main class's, and a sub-class without one inherits it.

Signed-off-by: Jiwon Park <jpark92@outlook.kr>
@uros-b

uros-b commented Aug 10, 2026

Copy link
Copy Markdown
Member

Thank you @j1wonpark!

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM

Comment thread python/pyspark/errors/utils.py Outdated
Comment thread python/pyspark/errors/tests/test_errors.py
The sub-class lookup allowed a sub-class to override the main class's
sqlState, which no error condition does and which the JVM side does not
support. Drop it so the Python and JVM readers resolve the same way.

Signed-off-by: Jiwon Park <jpark92@outlook.kr>

@nchammas nchammas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nitpick but: I would tweak the PR title to something a bit clearer (at least to me).

For example: "Make PySpark error sub-conditions inherit the parent condition error state"

@j1wonpark j1wonpark changed the title [SPARK-58684][PYTHON] Make get_sqlstate fall back to the main error class's sqlState [SPARK-58684][PYTHON] Make PySpark error sub-conditions inherit the parent condition error state Aug 11, 2026
@j1wonpark

Copy link
Copy Markdown
Contributor Author

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

@pan3793

pan3793 commented Aug 14, 2026

Copy link
Copy Markdown
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants