Repository navigation
fix: convert Arrow JSON in merge-insert full-fragment-rewrite fast path - #7473
Merged
wjones127 merged 1 commit intoJul 6, 2026
Merged
Conversation
xloya
force-pushed
the
upstream-pr/json-merge-insert-whole-row
branch
from
June 25, 2026 08:06
63fdb9b to
ce31699
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
wjones127
self-requested a review
July 2, 2026 21:35
wjones127
approved these changes
Jul 6, 2026
wjones127
left a comment
Contributor
There was a problem hiding this comment.
This looks good. Thanks!
Xuanwo
added a commit
that referenced
this pull request
Sep 23, 2026
…ndary (#9478) Part of #7073. ## Problem Arrow JSON input (`arrow.json` text) must be converted to Lance JSONB before it is encoded, but each dataset write path opted into the conversion on its own. A path that forgot it wrote UTF-8 bytes into a column whose file schema says `LargeBinary` + `lance.json`, and the file was only found to be corrupt on read (#7469–#7473 each fixed one such path). Nothing in the file writers noticed: the current-format writers (2.0–2.3) check column presence and nullability, but never compare an array's type or extension with the file schema. ## Behavior - Every current-format file writer checks each batch (and each `write_column` array) against the file schema before encoding. A mismatch returns `Error::InvalidInput` whose source is a `FieldTypeMismatch` naming the field path and the expected and actual Arrow type and extension. The check reads only types and field metadata, never values. - Dataset writes convert Arrow JSON to JSONB (and top-level view arrays to offset arrays, as today) in one place: the current-format data file writer that all dataset data files now go through, including single-fragment creation and data file parts. The per-call-site conversions in the write, append, fragment-create, updater and merge-insert paths are gone. - A Lance `json` field records `lance.json` whether it was created from `arrow.json` or `lance.json` input, so schemas derived directly from caller data match the stored layout. ## Tradeoffs - The check lives in `lance-file` rather than the dataset writer because it is the only layer every data file passes through (dataset writes, data file parts, and direct `lance-file` users), and it owns the file schema that readers trust. The conversion stays in the dataset layer: it is table semantics, and the file layer only rejects input that skipped it. - Names and nullability of nested fields are not compared, since encoders address children by position and check nulls against values. `Utf8View`/`BinaryView` are accepted where the schema says `Utf8`/`Binary`, because the encoders already write them in the offset layout. Blob v2 fields are checked only at the struct level: the encoder receives the descriptor struct from blob preprocessing, not the struct the file schema records, and validates it itself. - The full check runs once per writer and again only when a batch's schema differs from the last accepted one; later batches cost a pointer or schema equality check. Measured on the first batch, it adds about 0.05 µs per flat column and 0.3 µs per `struct<int, json>` column, which is 1–4% of encoding one flat batch and 7–13% of encoding one small nested JSON batch. That cost is paid once per file. - `write_column` receives a bare array, so the column's own extension cannot be checked there; nested extensions can. - Two write paths still convert early, because they combine caller data with values read back from storage before writing: partial-fragment merge-insert (interleave) and `update_columns` (hash-join fallback). They are no longer the only guard. - Legacy (V1) files keep their existing schema compatibility check and are not changed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A merge-insert touching a JSON column where ALL rows in a fragment are updated writes corrupt data and triggers a decoder panic on subsequent reads.
Root cause
The "all rows updated" fast path in
handle_fragmentwrote Arrow JSON (Utf8, i32 offsets) into a column whose schema declares Lance JSON (LargeBinary, i64 offsets) without conversion.Fix
Convert Arrow JSON columns to Lance JSON before writing in that fast path.
Test
Rust
test_merge_insert_full_fragment_rewrite_with_json_columns; Pythontest_merge_insert_full_fragment_rewrite_json_e2e.