Skip to content

Conversation

@garlandz-db
Copy link
Contributor

@garlandz-db garlandz-db commented Oct 22, 2025

What changes were proposed in this pull request?

Spark connect client cannot properly read the error details when the server has a new error. This is because it relies on an internal ErrorClassReader which pulls from a local json file that contains the error details at that time. However this json file can become out of date when the server throws a new error.

This PR ensures all exceptions will contain an optional sql state property and override the getSqlState to method to first check if the sql state is defined, otherwise use the original functionality (i.e. read from json file). To ensure backward compatibility, all sql states are initially None.

We will also make a client side change in #52589 so that when client receives an exception, it will read the sql state first when reconstructing the exception and populate that exceptions field. Now older clients can carry sql state information for newer servers!

Why are the changes needed?

Does this PR introduce any user-facing change?

How was this patch tested?

Was this patch authored or co-authored using generative AI tooling?

garlandz-db and others added 2 commits October 16, 2025 15:40
This change adds an optional sqlState parameter to the constructors of all
SparkThrowable implementations. The getSqlState method is overridden to check
the provided property first before falling back to the errorClassReader.

Implementation:
- Added optional sqlState parameter to all exception constructors
- For Scala: sqlState: Option[String] = None
- For Java: String sqlState with null as default
- Override getSqlState() to prioritize the custom property:
  * Scala: sqlState.getOrElse(super.getSqlState)
  * Java: sqlState != null ? sqlState : SparkThrowable.super.getSqlState()

Modified Files:
- SparkException.scala: 18 exception classes updated
- StreamingQueryException.scala
- SqlScriptingException.scala
- SparkOutOfMemoryError.java
- KafkaExceptions.scala: 2 exception classes
- SparkFileAlreadyExistsException.scala

Test Coverage:
- Added 6 tests to SparkThrowableSuite covering Scala and Java exceptions
- Created KafkaExceptionsSuite with 3 tests for Kafka-specific exceptions
- Tests verify custom SQL state takes precedence over errorClassReader
- Tests verify fallback to errorClassReader when no custom state provided

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@garlandz-db garlandz-db changed the title Add optional sqlstate to sparkthrowables [SPARK-53882][CONNECT] Add optional sqlstate to sparkthrowables Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant