Skip to content

[SPARK-55275] SQL State Coverage: IllegalStateException#54056

Closed
garlandz-db wants to merge 9 commits intoapache:masterfrom
garlandz-db:SPARK-55275
Closed

[SPARK-55275] SQL State Coverage: IllegalStateException#54056
garlandz-db wants to merge 9 commits intoapache:masterfrom
garlandz-db:SPARK-55275

Conversation

@garlandz-db
Copy link
Copy Markdown
Contributor

@garlandz-db garlandz-db commented Jan 29, 2026

What changes were proposed in this pull request?

Update IllegalStateException => SparkIllegalStateException in spark connect layer

Why are the changes needed?

This keeps the Spark Connect layer more traceable for errors

Does this PR introduce any user-facing change?

Yes. Changes exception type to their Spark equivalent

How was this patch tested?

Updated testing

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

Yes

@github-actions
Copy link
Copy Markdown

JIRA Issue Information

=== Improvement SPARK-55275 ===
Summary: add a specific SQL state for IllegalStateException errors at ExecuteEventsManager.assertStatus to ensure reliable error reporting
Assignee: None
Status: Open
Affected: ["4.0.2"]


This comment was automatically generated by GitHub Actions

@garlandz-db garlandz-db force-pushed the SPARK-55275 branch 2 times, most recently from 6d21971 to ae01b8c Compare February 5, 2026 08:37
@@ -90,7 +90,7 @@ class SparkDeclarativePipelinesServerTest extends SparkConnectServerTest with St
if (iter.hasNext) {
iter.next()
} else {
throw new IllegalStateException(s"Invalid response: $iter")
throw IllegalStateErrors.noBatchesAvailable()
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.

iter is missing?

@garlandz-db garlandz-db force-pushed the SPARK-55275 branch 3 times, most recently from aa03ab3 to 3ad3fb4 Compare February 9, 2026 13:25
@@ -332,7 +333,7 @@ case class SessionHolder(userId: String, sessionId: String, session: SparkSessio
// called only once, since removing the session from SparkConnectSessionManager.sessionStore is
// synchronized and guaranteed to happen only once.
if (closedTimeMs.isDefined) {
throw new IllegalStateException(s"Session $key is already closed.")
throw IllegalStateErrors.sessionAlreadyClosed(sessionId)
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.

key is missing?

"value" -> value,
"context" -> context))

def cleanerAlreadySet(queryKey: String): SparkIllegalStateException =
Copy link
Copy Markdown
Contributor

@heyihong heyihong Feb 9, 2026

Choose a reason for hiding this comment

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

I was wondering if it makes sense to have two message parameters—userId and sessionId—instead of queryKey.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the query id and run id are whats previously thrown. we can also include that

sessionId: $sessionId with status ${status}
is not within statuses $validStatuses for event $eventStatus
""")
throw IllegalStateErrors.sessionStateTransitionInvalid(status.toString, eventStatus.toString)
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.

sessionId and validStatuses are missing?

@garlandz-db garlandz-db requested a review from heyihong February 10, 2026 08:29
@garlandz-db garlandz-db force-pushed the SPARK-55275 branch 4 times, most recently from 28c7b12 to 684123f Compare February 10, 2026 09:12
@garlandz-db garlandz-db changed the title [SPARK-55275] SQL State Coverage: IllegalStateException [SPARK-55275] SQL State Coverage: IllegalStateException AND InvalidPlanInput Feb 10, 2026
Copy link
Copy Markdown
Contributor

@heyihong heyihong left a comment

Choose a reason for hiding this comment

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

Left some final comment

Comment thread common/utils/src/main/resources/error/error-conditions.json
@heyihong
Copy link
Copy Markdown
Contributor

heyihong commented Feb 13, 2026

Early LGTM — please fix the test failures accordingly. I also noticed a few unused subclasses (e.g., DATA_INTEGRITY_OPERATION_ID_MISMATCH, SESSION_MANAGEMENT_SERVER_SESSION_ID_CHANGED). Could you clean those up accordingly? One final thing: some error messages (e.g., “Attempting to stop the Spark Connect service that has not been started”) are being lost. Could you fix that as well?

@@ -46,11 +46,13 @@ object InvalidPlanInput {
InvalidPlanInput(
errorCondition = "INTERNAL_ERROR",
messageParameters = Map("message" -> message),
causeOpt = None)
causeOpt = None,
sqlState = Some("56K00"))
Copy link
Copy Markdown
Contributor

@heyihong heyihong Feb 13, 2026

Choose a reason for hiding this comment

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

On second thought, it may not be a good idea to include this custom mapping in the code. It breaks the assumption that each error condition corresponds to a single SQL state. You might also need to change the error condition to a new one and store this mapping in error-conditions.json.


def apply(errorCondition: String, messageParameters: Map[String, String]): InvalidPlanInput =
InvalidPlanInput(
errorCondition = errorCondition,
messageParameters = messageParameters,
causeOpt = None)
causeOpt = None,
sqlState = Some("56K00"))
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.

ditto

@heyihong
Copy link
Copy Markdown
Contributor

One good practice is to split a larger PR into smaller ones so that it is easier for reviewers to handle. In this case, it may be easier to review if we split the changes for IllegalStateExceptions and InvalidPlanInput into separate PRs.

@@ -455,8 +456,7 @@ object SparkConnectService extends Logging {
}

if (!started) {
throw new IllegalStateException(
"Attempting to stop the Spark Connect service that has not been started.")
throw IllegalStateErrors.serviceNotStarted()
Copy link
Copy Markdown
Contributor

@heyihong heyihong Feb 13, 2026

Choose a reason for hiding this comment

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

Friendly ping on this. It seems that some error messages (e.g., “Attempting to stop the Spark Connect service that has not been started”) are still being lost

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated good catch!

@garlandz-db garlandz-db changed the title [SPARK-55275] SQL State Coverage: IllegalStateException AND InvalidPlanInput [SPARK-55275] SQL State Coverage: IllegalStateException Feb 13, 2026
@garlandz-db garlandz-db force-pushed the SPARK-55275 branch 2 times, most recently from 4051ebc to 8277b78 Compare February 16, 2026 16:09
val eventSender = new PipelineEventSender(mockObserver, mockSessionHolder)
eventSender.shutdown()
intercept[IllegalStateException] {
intercept[SparkIllegalStateException] {
Copy link
Copy Markdown
Contributor

@hvanhovell hvanhovell Feb 23, 2026

Choose a reason for hiding this comment

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

You don't have to do this right? We are still throwing an IllegalStateException right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i did it to validate the changes but yes we can change it back

import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.connect.service.{ExecuteStatus, SessionStatus}

class IllegalStateErrorsSuite extends SparkFunSuite {
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.

I am not sure I love this class. It is super mechanical, and relatively low yield. Don't we have existing tests for this, that we can tighten up?

Copy link
Copy Markdown
Contributor

@hvanhovell hvanhovell left a comment

Choose a reason for hiding this comment

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

LGTM

@hvanhovell
Copy link
Copy Markdown
Contributor

@garlandz-db can you look at the test failures?

garlandz-db and others added 8 commits February 26, 2026 21:49
…alStateException

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move sqlState before subClass to match Jackson ORDER_MAP_ENTRIES_BY_KEYS
alphabetical ordering required by SparkThrowableSuite.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@garlandz-db
Copy link
Copy Markdown
Contributor Author

CI is flaking. rebasing off master

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.

4 participants