← Back to Pull requests

fix: [branch-1.1] decode invalid UTF-8 in nested Parquet BINARY values read as strings (#7106) #7340

Closed
unknown closed this pull request without merging on Oct 31, 2026 02:43 UTC
View on GitHub
unknown unknown commented on Oct 30, 2026 15:55 UTC
Author

Which issue does this PR close?

Backport of #7106 to branch-1.1. Part of #7032 (the nested values) and #4764.

Rationale for this change

When a Parquet BINARY column without the UTF8 annotation is read as a string, through a read schema or spark.sql.parquet.binaryAsString=true, the native scan converts nested values (struct fields, list elements, map keys and values) in parquet_convert_array. That fell through to Arrow's safe cast, which turns invalid UTF-8 into NULL, so those values silently became NULL where Spark keeps the bytes. branch-1.1 has this bug. See #7106 for the full rationale.

The fix also goes to branch-1.2 in #7339, opened together with this one. Per the backporting guide, this one should not merge before that one is ready.

What changes are included in this PR?

The cherry-pick of 621b9ccdb4658ad2671e4e88e5c51da67e3c8fbc from main. branch-1.1 differs from main in several places the source commit touches, so these parts were applied by hand:

  • native/core/src/parquet/parquet_support.rs: on this branch parquet_convert_array_impl, parquet_convert_struct_to_struct and parquet_convert_map_to_map return a bare ArrayRef, not the (ArrayRef, bool) field-overlap pair that #7085 introduced on main. The new in_map_key parameter is threaded through the branch's signatures, and the new Binary/LargeBinary/BinaryView and Dictionary arms return a bare array. The helper functions referenced_dictionary_values and decoded_bytes and the four new unit tests are taken verbatim from the source commit. The SparkError import conflict was resolved the same way as on branch-1.2.

  • native/core/src/parquet/parquet_exec.rs: the new test nested_arrow_binary_types_read_as_string_decode_invalid_utf8 is taken from the source commit, with the three trailing datetime-rebase arguments dropped from its init_datasource_exec call, because that function doesn't take them on this branch.

  • native/spark-expr/src/conversion_funcs/cast.rs: only the import line conflicted. main imports format_decimal_str there and this branch doesn't; the backport adds only the arrow::buffer imports the fix needs. The rest of the file's changes applied cleanly.

  • On this branch SparkCastOptions::new, SparkCastOptions::new_without_timezone and SparkParquetOptions::new still take the allow_incompat flag that main has since removed, so the backported code and tests pass false to them.

  • docs/source/user-guide/latest/compatibility/index.md: this branch's "Strings with non-UTF-8 bytes" section predates the per-source list that main has, so the source commit's new bullet is folded into the existing paragraph as a sentence: nested BINARY values read as strings are now decoded, top-level values and map keys are not checked, with a link to #7032.

  • docs/source/user-guide/latest/parquet.md does not exist on this branch, so its changes (the #7032 known-issue entry and the #7254 dictionary limit) are dropped.
  • How are these changes tested?

    The tests from #7106: the Rust unit tests in parquet_support.rs, parquet_exec.rs and cast.rs, and the new ParquetReadSuite test "native scan decodes invalid UTF-8 in nested BINARY read as string".

    Locally on this branch:

  • cargo check --all-targets, cargo clippy --all-targets --workspace -- -D warnings and cargo fmt --check in native/ pass.

  • The parquet_support and parquet_exec tests in datafusion-comet (22 tests) and the cast tests in datafusion-comet-spark-expr (95 tests) pass.

  • ./mvnw test -Dtest=none -Dsuites="org.apache.comet.parquet.ParquetReadV1Suite native scan decodes" passes after make core.
  • 🤖 Generated with Claude Code

    Diff: 467 lines (+350 / -117) across 5 files Reviewer: andygrove Review duration: 647m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 467 lines diff across 5 files
    0.46
    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%
    60%
    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.368
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #7340"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 45.6% (MEDIUM) · Higher = larger blast radius
    45.6%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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% · Safe to merge
    18%