← Back to Pull requests

[SPARK-57195][SQL] Surface MALFORMED_CSV_RECORD instead of ArrayIndexOutOfBoundsException in CSV schema inference #56260

Closed
unknown closed this pull request without merging on Jun 14, 2026 17:58 UTC
View on GitHub
unknown unknown commented on Jun 01, 2026 23:24 UTC
Author

What changes were proposed in this pull request?

CSV schema inference can fail with an uncaught java.lang.ArrayIndexOutOfBoundsException when a row has more columns than maxColumns. SPARK-49444 added handling for the per-line UnivocityParser.parseLine path, but the schema-inference paths that tokenize with a raw Univocity CsvParser were never covered, so they still surface the internal exception.

This PR translates that exception into a MALFORMED_CSV_RECORD error across the remaining paths:

  • Adds a shared UnivocityParser.parseLine(tokenizer, line) helper that converts Univocity's ArrayIndexOutOfBoundsException (raised bare or wrapped in a TextParsingException) into MALFORMED_CSV_RECORD.

  • The bad record in the message is bounded to CSVOptions.MAX_ERROR_CONTENT_LENGTH

  • (the same bound Univocity uses).
  • Guards the streaming tokenizer UnivocityParser.convertStream, used by multiLine reads and multiLine schema inference.

  • Routes the non-multiLine inference path (TextInputCSVDataSource.inferFromDataset).
  • Note: Header rows are out of scope from this PR. A header over maxColumns still surfaces the raw AIOOBE (CSVHeaderChecker), a pre-existing gap.

    Why are the changes needed?

    Schema inference and multiLine reads crash with an internal ArrayIndexOutOfBoundsException for input that should produce a clean MALFORMED_CSV_RECORD error. SPARK-49444 only covered UnivocityParser.parseLine; the inference paths construct a raw CsvParser and call parseLine on it directly, bypassing that handling.

    Does this PR introduce _any_ user-facing change?

    Yes.

  • When a CSV row has more columns than maxColumns during schema inference (or a multiLine read), the surfaced error changes from an internal java.lang.ArrayIndexOutOfBoundsException to MALFORMED_CSV_RECORD (SQLSTATE KD000), consistent with the non-multiLine per-row read path since SPARK-49444. This is a change relative to all released versions.

  • A maxCharsPerColumn overflow on the guarded paths also changes error class (TextParsingException -> MALFORMED_CSV_RECORD), because the direct-cause AIOOBE check can't distinguish it from maxColumns; 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

    Diff: 336 lines (+252 / -84) across 4 files Reviewer: yyanyy Review duration: 18394m
    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
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.2% (MEDIUM) · Higher = larger blast radius
    42.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.3% · Safe to merge
    18.3%
    Repository