Repository navigation
test(compaction): cover metadata-only column addition fallback - #8479
Conversation
Signed-off-by: pjdurden <[email protected]>
|
ACTION NEEDED The PR title and description are used as the merge commit message. Please update your PR title and description to match the specification. For details on the error please inspect the "PR Title Check" action. |
There was a problem hiding this comment.
Pull request overview
Fixes a correctness bug in the dataset compaction “binary copy” fast path where schema evolution via metadata-only add_columns / drop_columns could produce compacted files whose manifest column mapping referenced non-existent physical columns, causing subsequent full scans to fail with out-of-range projection errors.
Changes:
- Add a guard in
can_use_binary_copy_currentto require that the input files’(fields, column_indices)mapping matches the dataset schema’s physical column layout; otherwise binary copy is disabled and compaction falls back to re-encode. - Update the binary copy precondition documentation to reflect the new schema-layout requirement.
- Add a regression test covering metadata-only
add_columnsfollowed by compaction, assertingForceBinaryCopyerrors andTryBinaryCopysucceeds and scans correctly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| rust/lance/src/dataset/optimize.rs | Disables binary-copy compaction when file mappings don’t match the dataset schema’s physical layout to prevent invalid projections after schema evolution. |
| rust/lance/src/dataset/optimize/tests/binary_copy.rs | Adds regression coverage for metadata-only add_columns + compaction and validates post-compaction full scan behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The regression only checked the column the bad projection tripped on and the newly added all-null one, so a re-encode that corrupted an existing column would still pass. Signed-off-by: pjdurden <[email protected]>
|
Agreed on the scope caveat, and I would rather state the claim narrowly than argue it. What this PR claims: binary copy can describe a compacted file with a column mapping the file does not have, and the guard stops it at the eligibility boundary. That part is reproducible on its own. With the guard reverted to the base revision, the added test fails, because With the guard it passes in 0.11s. What it does not claim: it does not establish that #8281's reporter was in binary-copy mode, it does not fix the all-null dictionary failure during re-encode, and it does not recover files already written with a bad mapping. Those should stay tracked on #8281 separately, and I am happy to relabel this as preventive hardening rather than a fix for that issue if that is the more accurate framing. Also addressed the review note: the test now asserts that the pre-existing column |
## Summary - require binary-copy inputs to use the physical column mapping derived from the dataset schema - let `TryBinaryCopy` safely fall back to re-encoding when files use another physical column order - add a Decimal128/UInt64 regression covering two uniformly reordered fragments and value round-tripping ## Root cause Binary-copy eligibility only required source files to agree with one another. The copy loop preserved their physical page order, but output metadata was regenerated in dataset-schema order, so uniformly reordered source files crossed logical columns after compaction. ## Related work PR #8479 proposes the same eligibility invariant for the separate metadata-only schema-evolution scenario in #8281. This repair is tied to the direct public-API reordered-column reproduction in #8501 and adds regression coverage for that distinct trigger. ## Validation - `cargo test -p lance dataset::optimize::tests::binary_copy` (19 passed) - `cargo fmt --all -- --check` - `cargo clippy --all --tests --benches -- -D warnings` Fixes #8501 <!-- lance-gatekeeper-fix:v1 agent=25608d6e39ef7bff453cc3ae371d5553 generation=1 --> Co-authored-by: Gatefixer <312823363+lance-gatefixer[bot]@users.noreply.github.com> Co-authored-by: Xuanwo <[email protected]>
## Summary - defer empty-dictionary reconstruction until buffered chunks are grouped for a page - canonicalize hidden null-key payloads and reuse a neighboring real dictionary when available - cover mixed valued/all-null chunks, sliced arbitrary key payloads, and v2.3 compaction ## Root cause A metadata-only all-null Dictionary<Int32, Utf8> column is synthesized with null keys and an empty values array. The structural encoder records key validity as rep/def levels and then removes the Arrow null bitmap. That exposes key payloads which may be arbitrary under Arrow nulls and cannot reference an empty dictionary. Adding a nullable placeholder per input chunk avoids the initial bounds error but fails when the accumulation queue combines that chunk with valued dictionary data, because the merged dictionary values become an unsupported nullable block. ## Fix Empty dictionary chunks now retain key validity until the buffered page is formed. At flush time their keys are rebuilt as validity-free zeroes and attached to an adjacent non-empty dictionary without adding values. An entirely empty page receives one zeroed non-null placeholder value. Rep/def preserves the logical nullness, so replacement keys are never exposed. The flush-time reconstruction follows the validated approach in #8010. ## Scope This repairs the independently reproduced re-encode precursor discovered while investigating #8281. It does not resolve the reported post-compaction projection mismatch; #8479 addresses the separate binary-copy mapping path, so #8281 should remain open. ## Validation - cargo test -p lance-encoding encodings::logical::primitive::tests:: (79 passed) - cargo test -p lance test_compact_metadata_only_all_null_dictionary - cargo fmt --all -- --check - cargo clippy --all --tests --benches -- -D warnings Refs #8281 Refs #7906 <!-- lance-gatekeeper-fix:v1 agent=2658ca47874be281f1a47f1e1b8e61ef generation=1 --> --------- Co-authored-by: Gatefixer <312823363+lance-gatefixer[bot]@users.noreply.github.com> Co-authored-by: Beau Hartshorne <[email protected]> Co-authored-by: Xuanwo <[email protected]>
## Summary - defer empty-dictionary reconstruction until buffered chunks are grouped for a page - canonicalize hidden null-key payloads and reuse a neighboring real dictionary when available - cover mixed valued/all-null chunks, sliced arbitrary key payloads, and v2.3 compaction ## Root cause A metadata-only all-null Dictionary<Int32, Utf8> column is synthesized with null keys and an empty values array. The structural encoder records key validity as rep/def levels and then removes the Arrow null bitmap. That exposes key payloads which may be arbitrary under Arrow nulls and cannot reference an empty dictionary. Adding a nullable placeholder per input chunk avoids the initial bounds error but fails when the accumulation queue combines that chunk with valued dictionary data, because the merged dictionary values become an unsupported nullable block. ## Fix Empty dictionary chunks now retain key validity until the buffered page is formed. At flush time their keys are rebuilt as validity-free zeroes and attached to an adjacent non-empty dictionary without adding values. An entirely empty page receives one zeroed non-null placeholder value. Rep/def preserves the logical nullness, so replacement keys are never exposed. The flush-time reconstruction follows the validated approach in lance-format#8010. ## Scope This repairs the independently reproduced re-encode precursor discovered while investigating lance-format#8281. It does not resolve the reported post-compaction projection mismatch; lance-format#8479 addresses the separate binary-copy mapping path, so lance-format#8281 should remain open. ## Validation - cargo test -p lance-encoding encodings::logical::primitive::tests:: (79 passed) - cargo test -p lance test_compact_metadata_only_all_null_dictionary - cargo fmt --all -- --check - cargo clippy --all --tests --benches -- -D warnings Refs lance-format#8281 Refs lance-format#7906 <!-- lance-gatekeeper-fix:v1 agent=2658ca47874be281f1a47f1e1b8e61ef generation=1 --> --------- Co-authored-by: Gatefixer <312823363+lance-gatefixer[bot]@users.noreply.github.com> Co-authored-by: Beau Hartshorne <[email protected]> Co-authored-by: Xuanwo <[email protected]>
# Conflicts: # rust/lance/src/dataset/optimize.rs # rust/lance/src/dataset/optimize/tests/binary_copy.rs
|
merged current main in (a310e61, no force-push). #8510 landed the same layout check in what's left is coverage #8510 doesn't have: its test reorders physical columns, this one does a metadata-only |
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The compatibility checks now track actual reader support: 15.0.0b2 and newer can use the BITMAP/LABEL_LIST row-address format introduced by #9814, while earlier readers retain full-scan fallback checks.
The compaction test still adds distinct V2.0–V2.3 coverage of forced-copy rejection and persisted fallback mappings for the production guard already merged in #8510. This revision changes tests only.
Xuanwo
left a comment
There was a problem hiding this comment.
Verified the V2.0-V2.3 compaction matrix, persisted fallback mapping, ForceBinaryCopy rejection, and the beta.2 row-address reader capability boundary. Targeted Rust tests, Python capability checks, and both language lints pass. All applicable checks are green on this head, and the test-only changes match the production guard already on main.
## Summary - require binary-copy inputs to use the physical column mapping derived from the dataset schema - let `TryBinaryCopy` safely fall back to re-encoding when files use another physical column order - add a Decimal128/UInt64 regression covering two uniformly reordered fragments and value round-tripping ## Root cause Binary-copy eligibility only required source files to agree with one another. The copy loop preserved their physical page order, but output metadata was regenerated in dataset-schema order, so uniformly reordered source files crossed logical columns after compaction. ## Related work PR lance-format#8479 proposes the same eligibility invariant for the separate metadata-only schema-evolution scenario in lance-format#8281. This repair is tied to the direct public-API reordered-column reproduction in lance-format#8501 and adds regression coverage for that distinct trigger. ## Validation - `cargo test -p lance dataset::optimize::tests::binary_copy` (19 passed) - `cargo fmt --all -- --check` - `cargo clippy --all --tests --benches -- -D warnings` Fixes lance-format#8501 <!-- lance-gatekeeper-fix:v1 agent=25608d6e39ef7bff453cc3ae371d5553 generation=1 --> Co-authored-by: Gatefixer <312823363+lance-gatefixer[bot]@users.noreply.github.com> Co-authored-by: Xuanwo <[email protected]> (backported from commit c4086ca, upstream lance-format#8510; adapted to release-10.0.0) Adapted: release-10.0.0 has no lance_file::versions::data_file_columns, so binary_copy::data_file_columns ports it: the (fields, column_indices) the release-10.0.0 writer records for the dataset schema, with every field in pre-order for v2.0 and only leaves, blobs and packed structs for v2.1+. test_binary_copy_packed_struct_column_mapping does not exist on release-10.0.0 and is not added. Adds test_binary_copy_falls_back_after_drop_columns for the drop_columns route, where the data files keep the dropped column and binary copy indexed past the schema's columns.
Adds regression coverage for a metadata-only
AllNullscolumn addition followed by compaction across Lance file versions V2.0, V2.1, V2.2, and V2.3.The test verifies that:
ForceBinaryCopyrejects source files whose physical mapping does not match the evolved dataset schema.TryBinaryCopyfalls back to re-encoding and persists the schema's full field and column mapping.The Python scalar-index compatibility matrix now treats
15.0.0b2as the first reader that supports the row-address format. Earlier readers must still fall back to a full scan, while15.0.0b2and newer must use the index.This is test-only coverage. The production eligibility guard is already on
mainfrom #8510; the compaction coverage's unique value is the four-version matrix plus explicitForceBinaryCopyrejection.