[SPARK-57195][SQL] Surface MALFORMED_CSV_RECORD instead of ArrayIndexOutOfBoundsException in CSV schema inference #56260
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.42) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 336 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.348
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #56260"
general
weight: 0.35
yyanyy
What changes were proposed in this pull request?
CSV schema inference can fail with an uncaught
java.lang.ArrayIndexOutOfBoundsExceptionwhen a row has more columns thanmaxColumns. SPARK-49444 added handling for the per-lineUnivocityParser.parseLinepath, but the schema-inference paths that tokenize with a raw UnivocityCsvParserwere never covered, so they still surface the internal exception.This PR translates that exception into a
MALFORMED_CSV_RECORDerror across the remaining paths:UnivocityParser.parseLine(tokenizer, line)helper that converts Univocity'sArrayIndexOutOfBoundsException(raised bare or wrapped in aTextParsingException) intoMALFORMED_CSV_RECORD.(the same bound Univocity uses).
UnivocityParser.convertStream, used bymultiLinereads andmultiLineschema inference.multiLineinference path (TextInputCSVDataSource.inferFromDataset).Note: Header rows are out of scope from this PR. A header over
maxColumnsstill surfaces the raw AIOOBE (CSVHeaderChecker), a pre-existing gap.Why are the changes needed?
Schema inference and
multiLinereads crash with an internalArrayIndexOutOfBoundsExceptionfor input that should produce a cleanMALFORMED_CSV_RECORDerror. SPARK-49444 only coveredUnivocityParser.parseLine; the inference paths construct a rawCsvParserand callparseLineon it directly, bypassing that handling.Does this PR introduce _any_ user-facing change?
Yes.
maxColumnsduring schema inference (or amultiLineread), the surfaced error changes from an internaljava.lang.ArrayIndexOutOfBoundsExceptiontoMALFORMED_CSV_RECORD(SQLSTATEKD000), consistent with the non-multiLineper-row read path since SPARK-49444. This is a change relative to all released versions.TextParsingException->MALFORMED_CSV_RECORD), because the direct-cause AIOOBE check can't distinguish it frommaxColumns; the bad-record content is bounded to 1000 chars.How was this patch tested?
Added unit tests in CSVSuite covering schema inference for the multiLine and non-multiLine paths, plus the multiLine read path, asserting MALFORMED_CSV_RECORD instead of a raw ArrayIndexOutOfBoundsException.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Anthropic), Claude Opus 4.8