[SPARK-57519][CORE] Fix NoSuchElementException in ErrorClassesJsonReader.isValidErrorClass for error classes without sub-classes#56583
Open
LuciferYang wants to merge 1 commit into
Conversation
…der.isValidErrorClass for error classes without sub-classes `isValidErrorClass` called `info.subClass.get` on the sub-class `Option`, which threw `NoSuchElementException` when a main error class exists but defines no sub-classes and is queried with a two-part name (`MAIN.SUB`). This is reachable from user SQL: SQL scripting handler declarations validate two-part condition names via `SparkThrowableHelper.isValidErrorClass`, so the internal exception leaked instead of the intended `conditionNotFound` error. Replace `info.subClass.get.contains(subClass)` with `info.subClass.exists(_.contains(subClass))`, which returns `false` when no sub-classes are defined. Add a regression test in `SparkThrowableSuite`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
ErrorClassesJsonReader.isValidErrorClasschecks a two-part error class name (MAIN.SUB) withinfo.subClass.get.contains(subClass). When the main class has no sub-classes,info.subClassisNone, so.getthrowsNoSuchElementException.This PR changes that to
info.subClass.exists(_.contains(subClass)), which returnsfalsein that case instead of throwing, and adds a test toSparkThrowableSuite.Why are the changes needed?
isValidErrorClassis meant to return a boolean, but it threw for this input. It is reachable from user SQL: SQL scripting handler declarations validate two-part condition names throughSparkThrowableHelper.isValidErrorClass(inAstBuilder), and so doesRAISE_ERROR. As a result a name likeDIVIDE_BY_ZERO.X(a real top-level error class with no sub-classes) surfaced an internalNoSuchElementExceptioninstead of the intended "condition not found" error.Does this PR introduce any user-facing change?
Yes. Validating a two-part error condition name whose main class has no sub-classes no longer throws
NoSuchElementException; it returnsfalse, so the caller can report the proper error. Inputs that already returned without throwing are unaffected.How was this patch tested?
Added a unit test in
SparkThrowableSuitethat covers a main class without sub-classes, a main class with sub-classes (valid and unknown sub-class), unknown main classes, and malformed names.build/sbt 'core/testOnly *SparkThrowableSuite'passes (34 tests).Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)