Skip to content

test(compaction): cover metadata-only column addition fallback - #8479

Merged
Xuanwo merged 7 commits into
lance-format:mainfrom
pjdurden:fix/8281
Oct 27, 2026
Merged

Xuanwo merged 7 commits into
lance-format:mainfrom
pjdurden:fix/8281

Conversation

@pjdurden

@pjdurden pjdurden commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Adds regression coverage for a metadata-only AllNulls column addition followed by compaction across Lance file versions V2.0, V2.1, V2.2, and V2.3.

The test verifies that:

  • ForceBinaryCopy rejects source files whose physical mapping does not match the evolved dataset schema.
  • TryBinaryCopy falls back to re-encoding and persists the schema's full field and column mapping.
  • The fallback preserves all rows and both existing columns while reading the added column as all null.

The Python scalar-index compatibility matrix now treats 15.0.0b2 as the first reader that supports the row-address format. Earlier readers must still fall back to a full scan, while 15.0.0b2 and newer must use the index.

This is test-only coverage. The production eligibility guard is already on main from #8510; the compaction coverage's unique value is the four-version matrix plus explicit ForceBinaryCopy rejection.

Copilot AI lite review requested due to automatic review settings August 11, 2026 15:33
@github-actions

Copy link
Copy Markdown
Contributor

ACTION NEEDED
Lance follows the Conventional Commits specification for release automation.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_current to 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_columns followed by compaction, asserting ForceBinaryCopy errors and TryBinaryCopy succeeds 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.

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Aug 11, 2026
@pjdurden pjdurden changed the title Full scan fails with an out-of-range projection after adding a column and compacting fix(compaction): skip binary copy when files miss schema columns Aug 11, 2026
@github-actions github-actions Bot added the bug Something isn't working label Aug 11, 2026
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]>
@pjdurden

Copy link
Copy Markdown
Contributor Author

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 ForceBinaryCopy returns Ok(CompactionMetrics { fragments_removed: 2, fragments_added: 1, files_removed: 2, files_added: 1 }) where it must refuse:

called `Result::unwrap_err()` on an `Ok` value: CompactionMetrics { ... }

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 b round-trips through the fallback, not just a and the new all-null c.

Xuanwo added a commit that referenced this pull request Sep 1, 2026
## 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]>
Xuanwo added a commit that referenced this pull request Sep 3, 2026
## 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]>
valkum pushed a commit to instant-labs/lance that referenced this pull request Sep 9, 2026
## 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]>
@lance-gatekeeper lance-gatekeeper Bot removed K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Sep 17, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Sep 17, 2026
# Conflicts:
#	rust/lance/src/dataset/optimize.rs
#	rust/lance/src/dataset/optimize/tests/binary_copy.rs
@pjdurden

pjdurden commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

merged current main in (a310e61, no force-push). #8510 landed the same layout check in can_use_binary_copy while this was open, so I took main's version of optimize.rs and dropped mine; the diff against main is now only the test file.

what's left is coverage #8510 doesn't have: its test reorders physical columns, this one does a metadata-only add_columns (all-null, no data written), compacts, and asserts binary copy is skipped and both the new and the untouched column round-trip. happy to retitle this as test(compaction): ... if you'd rather take it that way.

@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 7, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 7, 2026
@wjones127 wjones127 added the critical-fix Bugs that cause crashes, security vulnerabilities, or incorrect data. label Oct 19, 2026
@Xuanwo Xuanwo changed the title fix(compaction): skip binary copy when files miss schema columns test(compaction): cover metadata-only column addition fallback Oct 27, 2026
@github-actions github-actions Bot added the chore label Oct 27, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 27, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 27, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 27, 2026
@github-actions github-actions Bot added the A-python Python bindings label Oct 27, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 27, 2026

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Xuanwo
Xuanwo merged commit 2ed8e2d into lance-format:main Oct 27, 2026
40 checks passed
mmatczuk pushed a commit to rerun-io/lance that referenced this pull request Nov 2, 2026
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-python Python bindings bug Something isn't working chore critical-fix Bugs that cause crashes, security vulnerabilities, or incorrect data. K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants