fix: [branch-1.1] decode invalid UTF-8 in nested Parquet BINARY values read as strings (#7106) #7340
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
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.368
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #7340"
general
weight: 0.35
andygrove
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) inparquet_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.1has this bug. See #7106 for the full rationale.The fix also goes to
branch-1.2in #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.1differs frommainin several places the source commit touches, so these parts were applied by hand:native/core/src/parquet/parquet_support.rs: on this branchparquet_convert_array_impl,parquet_convert_struct_to_structandparquet_convert_map_to_mapreturn a bareArrayRef, not the(ArrayRef, bool)field-overlap pair that #7085 introduced onmain. The newin_map_keyparameter is threaded through the branch's signatures, and the newBinary/LargeBinary/BinaryViewandDictionaryarms return a bare array. The helper functionsreferenced_dictionary_valuesanddecoded_bytesand the four new unit tests are taken verbatim from the source commit. TheSparkErrorimport conflict was resolved the same way as onbranch-1.2.native/core/src/parquet/parquet_exec.rs: the new testnested_arrow_binary_types_read_as_string_decode_invalid_utf8is taken from the source commit, with the three trailing datetime-rebase arguments dropped from itsinit_datasource_execcall, because that function doesn't take them on this branch.native/spark-expr/src/conversion_funcs/cast.rs: only the import line conflicted.mainimportsformat_decimal_strthere and this branch doesn't; the backport adds only thearrow::bufferimports the fix needs. The rest of the file's changes applied cleanly.SparkCastOptions::new,SparkCastOptions::new_without_timezoneandSparkParquetOptions::newstill take theallow_incompatflag thatmainhas since removed, so the backported code and tests passfalseto them.docs/source/user-guide/latest/compatibility/index.md: this branch's "Strings with non-UTF-8 bytes" section predates the per-source list thatmainhas, 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.mddoes 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.rsandcast.rs, and the newParquetReadSuitetest "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 warningsandcargo fmt --checkinnative/pass.parquet_supportandparquet_exectests indatafusion-comet(22 tests) and thecasttests indatafusion-comet-spark-expr(95 tests) pass../mvnw test -Dtest=none -Dsuites="org.apache.comet.parquet.ParquetReadV1Suite native scan decodes"passes aftermake core.🤖 Generated with Claude Code