Repository navigation
fix: reject field metadata updates that change how stored data decodes - #11331
Conversation
Readers take a field's layout from its metadata: the packed key (`packed` / `lance-encoding:packed`, honored on nested fields), the blob key (`lance-encoding:blob`) and the Blob v2 extension name. Data files keep the layout they were written with, but `UpdateConfig` and the Transaction V2 ConfigUpdate action applied field metadata without looking at those keys. Marking an existing struct or list packed made it read back as all nulls on 2.1+, marking an existing binary column a blob left it unreadable on every storage version, and a replace that dropped one of these keys either broke the column (2.0) or failed with a misleading column-index error (2.1+). Compare the schema before and after the field metadata updates, and refuse an update that flips any of these properties for an existing field. Whether a field can be packed follows its type, and packed counts as changed when either reader's view changes: the Lance schema accepts any truthy value, the Arrow-level struct decoder only "true". The check covers fields with no data yet too, because a concurrent append that read the old schema can still commit a file in the old layout, and its conflict check treats an UpdateConfig as compatible. Fields minted in the same composite operation may still be given any encoding.
Xuanwo
left a comment
There was a problem hiding this comment.
AI-assisted technical review of e10ffb8b
Two blockers remain from source inspection.
packed_markersand the 2.0 struct writer apply different rules for alias precedence and key presence. A metadata edit that passes the commit check can still change how a later append lays out the struct. Please validate against both the existing reader and writer interpretations, and cover the two spellings with ordinary metadata edits followed by append and reopen. Check the returned struct values as well as the commit result.- Every V2 composite commit calls
check_field_decoding_unchanged, including append-only transactions. It walks the new schema and performs a linearbefore.field_by_idlookup for each field. Please skip this work when the actions cannot change field metadata, and use one ID map or linear traversal when they can. Compare the final state and keep the commit-time protection for fields that were empty when the edit began.
Please also clarify the boundary for a complete same-ID re-encoding. The V2 TombstoneFieldData and AddDataFile contract already supports rebinding a field to rewritten files. A guard for metadata-only edits should preserve that operation. The Rust and Python replacement docs should tell callers to retain annotations needed to decode or interpret existing values, including extension-type metadata.
… re-encodes - Compare the 2.0 struct writer's reading of the packed keys as well: `packed` decides whenever present, and `lance-encoding:packed` packs a struct by being present at all. Edits that only it reads differently are now refused. - Run the decoding check on the V2 path only when a ConfigUpdate changes field metadata, with one id map instead of a lookup per field. - Allow a decoding change of a field the same operation re-encoded in full with TombstoneFieldData and AddDataFile. - Document what a field metadata replace must restate.
A same-id re-encode keeps the field's overlays in the old layout, and a writer staged against the old schema can still commit an old-layout file after it, so rewriting the base files does not make a marker change safe. Drop the exemption. A re-encode that keeps the markers still commits, together with other field metadata edits.
|
Thanks for the review. Addressed in 4ae1208 and b284d67: Alias precedence and key presence. The check now also compares the 2.0 struct writer's reading. That writer lets packed decide whenever it is present, and packs a struct that has lance-encoding:packed at all, even "false". Two edits used to pass the commit check and change how later appends lay out the struct: adding lance-encoding:packed: false to an unpacked struct, and adding packed: false beside lance-encoding:packed: true. Both are now rejected. test_packed_struct_edits_keep_appends_readable covers 2.0, 2.1 and 2.2 with both spellings. It makes ordinary edits, appends, reopens, and checks the returned struct values. |
|
Please keep the guard across all table defaults. I verified on AI-assisted review. |
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The mixed-version append clarification is confirmed: tables with a 2.1 or 2.2 default accept explicit 2.0 appends while retaining their default. The 2.0 writer check is therefore required across all table defaults.
Marker-changing re-encodes remain rejected, preventing the earlier overlay and stale-writer failures. Same-ID re-encodes that preserve the markers remain supported. No blocking findings.
|
Thanks for the review. Addressed in 4ae1208 and b284d67: Alias precedence and key presence. The check now also compares the 2.0 struct writer's reading. That writer lets packed decide whenever it is present, and packs a struct that has lance-encoding:packed at all, even "false". Two edits used to pass the commit check and change how later appends lay out the struct: adding lance-encoding:packed: false to an unpacked struct, and adding packed: false beside lance-encoding:packed: true. Both are now rejected. test_packed_struct_edits_keep_appends_readable covers 2.0, 2.1 and 2.2 with both spellings. It makes ordinary edits, appends, reopens, and checks the returned struct values. |
wjones127
left a comment
There was a problem hiding this comment.
Thanks for this, and for the thorough reproductions. Refusing decoding-marker changes on every existing field closes the stale-writer race without touching the conflict resolver, and the tests cover the cases well.
Nothing blocks from me. Non-blocking:
- I'd rather not add a fourth parser for the packed keys; raw-key immutability would avoid it (inline).
- suggestion: The write-time bugs under "Related, not fixed here" look like real data bugs:
packed: "1"structs can't be read back on 2.1+, and on 2.0 neither canlance-encoding:packed: "false"ones. Could you file an issue? I think the real fix is one canonical struct for a field's encoding configuration, with a single parse method that every reader and writer uses instead of checking metadata keys directly. That would fix these bugs, and if we later want to allow harmless edits, this check could compare parsed configs instead of raw keys. Fine as a follow-up. - The "Clear field metadata" rustdoc example now fails for packed and blob columns (inline).
- nitpick: The description is out of date after the last round. "Still allowed: setting or removing
packed: "false"" no longer holds forlance-encoding:packed: "false", or forpacked: "false"next tolance-encoding:packed: "true", and the Testing section missestest_packed_struct_edits_keep_appends_readable. Since it becomes the commit message, could you refresh and trim it?
| /// Whether the field can be packed comes from its type rather than its | ||
| /// children, so a struct that gains its first child or loses its last one | ||
| /// keeps its markers. Leaves ignore them. | ||
| fn packed_markers(field: &Field) -> (bool, bool, bool) { |
There was a problem hiding this comment.
suggestion: I'm a bit wary of adding a fourth parser for these keys. Today is_packed_struct in lance-core, is_packed_struct in lance-arrow, and the 2.0 writer each parse them differently, and packed_markers has to stay in step with all three. Could we avoid parsing here entirely and just treat the marker keys as immutable on existing fields? That would mean refusing any change to the raw value (including adding or removing it) of packed, lance-encoding:packed and lance-encoding:blob, and of ARROW:extension:name when either side is Blob v2. That's the rule we already use for the primary-key keys:
lance/rust/lance-table/src/transaction/action/config_update.rs
Lines 73 to 78 in b284d67
We'd lose a few harmless edits (alias swap, true -> TRUE), but it's easier to loosen later than to tighten.
There was a problem hiding this comment.
Done. packed_markers is gone, and the check no longer parses anything. On existing fields it now refuses any change, addition or removal of the raw value of packed, lance-encoding:packed and lance-encoding:blob, and of ARROW:extension:name when either side is Blob v2. That means the alias swap and true → TRUE are now refused. The test cases were updated to match.
| /// extension-type metadata (`ARROW:extension:name`, | ||
| /// `ARROW:extension:metadata`). A replace that changes how stored data | ||
| /// decodes is refused. Other extension-type metadata is not checked, and | ||
| /// dropping it makes readers return the values as their storage type. |
There was a problem hiding this comment.
suggestion: The "Clear field metadata" example on update_field_metadata now errors for packed and blob columns:
lance/rust/lance/src/dataset.rs
Lines 4048 to 4052 in b284d67
Maybe add a line there pointing to this restate rule, or drop the example? The Java updateFieldMetadata/replace docs could use the same note as Python.
There was a problem hiding this comment.
Added a note to the example saying a clear is refused for packed and blob fields and pointing to the restate rule on UpdateFieldMetadataBuilder::replace. Java has no updateFieldMetadata; field metadata goes through UpdateConfig.Builder.fieldMetadataUpdates, so I added the same note to its Javadoc.
| /// extension-type metadata (`ARROW:extension:name`, | ||
| /// `ARROW:extension:metadata`). A replace that changes how stored data | ||
| /// decodes is refused. Other extension-type metadata is not checked, and | ||
| /// dropping it makes readers return the values as their storage type. |
There was a problem hiding this comment.
thought: Another option for the clear/replace case would be for replace to carry the reserved encoding keys over when the new map leaves them out, and only error when the caller explicitly sets a different value. The "clear field metadata" example would keep working, and nobody's explicit write gets silently dropped. Just an idea, not needed for this PR.
There was a problem hiding this comment.
That would be nicer for callers. I've left it out here to keep this PR to the check itself, and noted it as an option in the follow-up issue.
… them Refuse any change, addition or removal of the raw value of packed, lance-encoding:packed and lance-encoding:blob on existing fields, and of ARROW:extension:name when either side is Blob v2, rather than comparing parsed packed readings. Document the restate rule on the clear example and the Java field metadata builder.
… constructors Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
update_field_metadata(and the deprecatedreplace_field_metadata) can change the metadata keys that tell readers how a column's stored data is laid out: the packed keys (packed,lance-encoding:packed), the blob key (lance-encoding:blob) and the Blob v2 extension name (ARROW:extension:name). Data files keep the layout they were written with, so after such an update the new version reads the column wrong:column_indexerror.Fix.
check_field_decoding_unchangedintransaction/validate.rscompares the schema before and after a field metadata update. For every existing field, it refuses the update with anInvalidInputerror if it changes, adds or removes the raw value ofpacked,lance-encoding:packedorlance-encoding:blob, or ofARROW:extension:namewhen either side is Blob v2. This is the same immutability rule the unenforced primary-key keys already use. The values are compared as stored, not parsed, because readers and writers parse the packed keys differently. A few harmless edits are refused as a result ("true"to"TRUE", switching to the other spelling of the packed key); it's easier to loosen that later than to tighten it.The check runs on both apply paths:
UpdateConfiginbuild_manifest, and a composite operation that contains aConfigUpdatewith field metadata, over the schema it builds. Fields created in the same operation take their layout from their first write. The error is raised aftercheck_blob_nesting, so a Blob v2 nested in a Map keeps its more specific error.Why every existing field, not only fields with data. An append, or a field re-encode, staged against the old schema can still commit a file in the old layout after the update lands, and overlays keep the old layout. Refusing the change on every existing field closes that race without changing the conflict resolver.
Behavior changes.
.replace(field, [])now errors for packed and blob columns. The Rust, Python and Java docs now say so.Follow-up: #11696 (packed key parsing differs between readers and writers).
Testing
validate.rs::test_changed_decoding_key: 16 cases (same value, unrelated key, mark/drop/false/case change/alias of the packed keys, struct, list and leaf, blob mark/drop/value, Blob v2 mark/drop, a non-blob extension).config_update.rs: the action path refuses a decoding change with or without stored data, and even when the field is fully re-encoded in the same operation. A re-encode that keeps the keys commits. A field created in the same operation can take any encoding. Changing a packed struct's children is not a decoding change.metadata.rs(each × 2.0 / 2.1 / 2.2):test_update_field_metadata_rejects_decoding_change: refused, nothing committed, data unchanged.test_update_field_metadata_rejects_decoding_change_without_data.test_update_field_metadata_keeps_decoding_when_allowed.test_update_field_metadata_rejects_dropping_blob_v2.test_packed_struct_edits_keep_appends_readable: edits that keep the packed key, under either spelling, followed by an append, read back from a reopened dataset; the alias swap andpacked: "false"are refused.test_dataset.py::test_field_metadata_rejects_decoding_change× 2.0 / 2.1 / 2.2.cargo test -p lance-table --libandcargo test -p lance --lib dataset::metadatapass.cargo fmtandcargo clippy -p lance-table -p lance --testsare clean apart from two existing Windows-only warnings in files this PR doesn't touch.