fix: decode malformed UTF-8 when adapting Parquet LargeBinary and BinaryView to strings #7718
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 617 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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.384
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #7718"
general
weight: 0.35
viirya
Which issue does this PR close?
Part of #7032 and the ingress policy in #4764. #7106 covers nested values. #6246 handles top-level columns with
spark.sql.parquet.binaryAsString=true. This PR covers top-level columns that reach Comet's schema adapter as binary, including reads with an explicit string schema and the setting off.Rationale for this change
A file can store an unannotated Parquet
BINARYcolumn namedvaluewith anARROW:schemahint ofDictionary(Int32, LargeBinary). Forspark.read.schema("value string").parquet(path), DataFusion passes the dictionary through to Comet. The scalar cast delegates itsLargeBinaryvalues to Arrow, which returns NULL for malformed UTF-8 in safe mode and an error in strict mode. For the bytes66 80 6F, Spark returns a non-null string that renders asf�o. The same conversion gap affectsLargeBinaryandBinaryViewwhen the file field is namedVALUEand Comet resolves it case-insensitively after DataFusion's exact-name check. DataFusion coercion, Arrow castWhat changes are included in this PR?
Route these file-to-string casts through the existing Parquet conversion used for nested values. The schema adapter and converter share the predicate for supported binary representations. Plain
Binaryat the top level already uses the scalar replacement decoder when it reaches the adapter. It applies JVM-compatible replacement decoding, including one U+FFFD for an encoded surrogate. Spark keeps the original bytes internally, sohex(value)yields66806Fin Spark and66EFBFBD6Fin Comet under the documented policy.Top-level dictionaries with
BinaryorLargeBinaryvalues now use the same Parquet conversion as nested dictionaries. It decodes values before expanding the original keys with Arrow'stake. For dictionaries above 64 KiB, Arrow's occupancy bitmap identifies the referenced entries. Comet calculates the full expanded byte count only iftakereports an offset overflow.The nested empty-dictionary panic and its regression test are isolated in #7808 for backport to
branch-1.2. This PR callsnormalized_keys()only after atakeoffset overflow. An empty dictionary has no valid keys, sotakeproduces null strings without that call.When replacing malformed bytes, each live input byte can expand to at most three UTF-8 bytes. If that bound exceeds the offset limit, Comet uses the JVM-compatible decoder to count the exact output bytes of each non-null value before allocating the string builder. It returns an offset error if the batch exceeds the limit and uses the exact size for a batch that fits. For binary views this check runs after Arrow materializes the raw binary values.
The 32-bit offset limit tracked in #7254 applies to these reads. At the default batch size, 8,192 references to one entry of 88,000
FFbytes expand to 2,162,688,000 replacement bytes. A query that previously succeeded with spurious nulls can now fail with a diagnostic suggesting a smallerspark.comet.batchSize. The Parquet and compatibility guides describe which top-level values reach the decoder.For a same-name plain
BINARYfield, DataFusion can requestUtf8directly from the reader before the adapter runs. That unchecked path is still open under #7032. Map-key identity is tracked in #7360.How are these changes tested?
ParquetReadSuiteextends the dictionary fixture to readDictionary(Int32, LargeBinary)with an explicit string schema andbinaryAsString=false. It compares collected strings with Spark, requires aCometNativeScanExec, and checkshex(value)andvalue IS NULLfor a repeated malformed value, valid bytes and a genuine null.LargeBinaryandBinaryView, an exact-nameDictionary(Int8, LargeBinary), and an all-null dictionary. It checkscafé, NULL and41 ED A0 80 42→A�B.BinaryandLargeBinarydictionaries with 8,191 references to a malformed 88,000-byte dictionary entry and one null key. It checks the complete decoded size and batch-size hint. Arrow checks offsets before allocating the expanded string buffer.Checked Rust and Scala formatting and
git diff --checklocally. Test execution is delegated to hosted CI.