← Back to Pull requests

fix: match SPARK-60262 when two requested fields select one Parquet field #7820

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Dec 01, 2026 22:45 UTC
Author

Which issue does this PR close?

Closes #7819.

Rationale for this change

SPARK-60262 (apache/spark#59510) is in Spark 4.0.5, 4.1.4, 4.2.1 and 4.3.0. With spark.sql.parquet.fieldId.read.enabled=true, ParquetReadSupport now fails the read with PARQUET_FIELD_REQUESTED_MORE_THAN_ONCE when two requested fields of one group, the root or a struct, resolve to the same Parquet field. That covers a field matched by id plus one matched by name, and two fields with the same id. Earlier releases read without an error.

Comet's native scan resolves these fields itself (#7196). It gave the file column to the id match and NULL to the name match, so on a Spark with SPARK-60262 Spark fails the read where Comet returned rows. The Parquet field claims tests compare Comet with Spark's own read, so on such a Spark most of them fail in that read, before Comet runs.

The conflict depends on the file's own schema, so scan planning cannot see it, and nothing in the plan tells Comet which behavior applies. Comet picks it by Spark version, as #7171 and #7522 do for other Spark fixes.

What changes are included in this PR?

  • SparkFixes.failsOnFieldRequestedMoreThanOnce holds the version check: 4.0.5+, 4.1.4+, 4.2.1+ and 4.3+, the same releases as the other fixes there.

  • NativeScanCommon.fail_on_field_requested_more_than_once carries it to the native scan. CometNativeScan sets it when field-id reads are on and the check holds, and it reaches SparkParquetOptions through init_datasource_exec.

  • FieldResolver finds the first file field that a second requested field selects, and every requested field that selects it, in request order. Spark does the same in checkNoFieldRequestedMoreThanOnce once it has clipped every requested field of the group, so the error is raised at the point where Spark raises it:

  • - A nested group records it in FieldMatches, and check_nested_conversion raises it after the sibling verdicts. A rejection of a field's shape still comes first, as in Spark, where clipping a struct over a primitive column fails with "is not a group". A deferred leaf rejection, which Spark raises only while it decodes, comes after it. The runtime struct conversion raises it before it converts a value.
    - The root is checked against the required roots in check_file_conversions, after the per-column checks. The scan's own adapter resolves against every root of the data schema, which Spark's pruned requested schema does not hold, so it never raises it. The footer step runs check_file_conversions for every file when the option is on.
  • SparkError::ParquetFieldRequestedMoreThanOnce and the Spark 4.x ShimSparkErrorConverter build Spark's SparkRuntimeException from its error class with Spark's three parameters, because QueryExecutionErrors.parquetFieldRequestedMoreThanOnceError is not in the Spark versions Comet builds against. It is wrapped in FAILED_READ_FILE.NO_HINT like the duplicate field id error next to it.

  • CometNativeReaderSuite: whenSparkReads runs a comparison with Spark only when Spark can read the file. When Spark fails with the new error, the test checks that Comet fails with the same message instead, from the native reader or, where the test expects a fallback, from Spark. The tests of a losing container and of a single-column projection over repeated ids need no change: Spark fails them earlier with its own error, or does not see the conflict.

  • parquet.md describes the behavior by release.
  • How are these changes tested?

  • Rust unit tests in field_resolver.rs follow Spark's own tests for the error: an id match and a name match in either order and in a case-sensitive read, two fields with one id around an unrelated field, every requester named in request order, no error for fields that select different or no file fields, backticks doubled in the message, and the precedence of a selection error over this one. Tests in schema_adapter.rs cover the order of a nested group's errors (shape first, deferred leaf after) and a root check that uses only the required roots.

  • error.rs checks the new error's full message against Spark's template, and its JSON parameters, error class and exception class.

  • SparkFixesSuite pins the version boundaries of the new check with the other three that share its releases.

  • CometNativeReaderSuite (184 tests) passes on Spark 3.5.9, 4.0.4, 4.0.5, 4.1.3, 4.1.4, 4.2.0 and 4.2.1, run on this change before it was rebased onto main at 785e96170. On 4.0.5, 4.1.4 and 4.2.1, which have SPARK-60262, the tests whose requested schema holds both fields read the file with Spark first, and the log of the 4.2.1 run holds Spark's SparkRuntimeException and Comet's native error for the same fields, which whenSparkReads compares. 3.5.9 needs whenSparkReads to capture the error in a var, because withSQLConf returns Unit before Spark 4.0, and its run used that form.

  • Before the rebase: cargo test for the native workspace passed apart from the five parquet::objectstore::http_metrics tests, which bind a loopback listener and could not do so where they ran, cargo fmt --all -- --check and cargo clippy --all-targets --workspace -- -D warnings were clean, and the scalafix check (-Pspark-4.1 clean compile test-compile scalafix:scalafix -Psemanticdb -Dscalafix.mode=CHECK) passed.

  • After the rebase onto main at 785e96170: cargo fmt --all -- --check is clean, cargo check --all-targets passes for datafusion-comet and datafusion-comet-common, and the Scala test-compile, with scalastyle and spotless, passes on the default profile and on -Pspark-3.5. The tests have not run since the rebase, so this PR's CI is their first run on top of current main.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: comphead Review duration: 1429m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #7820"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 27.7% · Safe to merge
    27.7%