Skip to content

fix(index): write zone map seeds when a seeded column gets a new data file - #9868

Merged
LuQQiu merged 5 commits into
lance-format:mainfrom
LuQQiu:lu/ent2893-seed-rewrite
Oct 14, 2026
Merged

LuQQiu merged 5 commits into
lance-format:mainfrom
LuQQiu:lu/ent2893-seed-rewrite

Conversation

@LuQQiu

@LuQQiu LuQQiu commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

If a column has a ZoneMap index with write seeds enabled, writing a new data file for that column should also write new seeds into that file.

Write seeds are small statistics collected while writing column values. They describe the values stored in that particular data file.

This PR makes column-update and refresh writers collect seeds, just as the append writer already does.

Example

Refreshing a column writes a replacement column file; it does not change the old file in place:

Before refresh:
Fragment F1 → old column file [NULL, NULL, NULL]

After refresh:
Fragment F1 → new column file [100, 200, 300]
                               + seeds for these new values

Before this PR, the replacement file was written without seeds. After this PR, an eligible column's new file contains both its data and the seeds collected from that data.

Writing paths covered

  • Append: preserves the existing seed-writing behavior.
  • Merge-insert column rewrites: collects seeds whether all or only some rows in a fragment are updated.
  • Fragment Updater: collects seeds from the batches written by the shared column-update path.
  • FileFragment::write_columns: collects seeds when staging replacement column files, including the path used for computed/function column refreshes.

A shared SeedCollector handles the same three steps in these writers:

Read the existing index's seed configuration
                    ↓
Write column batches and collect their statistics
                    ↓
Store seeds in the same data file before closing it

Seed collection uses the batches already being written; it does not require a separate scan.

New files, partial updates, and deletions

All writing paths above create new data files; they do not edit the old files in place. Seeds are stored inside the new file alongside the data they describe.

For a column rewrite, the fragment ID can stay the same. The affected column gets a replacement file; unrelated column files can be reused.

Updating only some rows still writes the complete affected column for that fragment:

Old column:             [5,   6, 7, 8]
Update the second row:      100
                            ↓
New column file:        [5, 100, 7, 8]
Seeds in that file:     statistics for this complete output

The partial-update path reads the old column to preserve unchanged values. Seed collection observes the resulting output batches, so it adds no extra read for statistics. It does not merge old min/max with the changed values or overwrite seeds in the old file.

Deleting rows is different: changing the deletion vector leaves the stored column values unchanged, so existing file seeds need not be regenerated. Their min/max still contain all remaining values, though the bounds may become wider than necessary. Null counts describe physical file rows, not the exact number of nulls among the rows still visible after deletions.

What stays unchanged

  • Seeds are collected only for eligible columns whose existing index enables them. use_seeds: false stays off.
  • Zone size, seed payload format, and null-position tracking are unchanged.
  • This does not enable seeds by default for unindexed columns.
  • This does not change seed consumption or ZoneMap index maintenance, and does not add a fragment-column statistics index.
  • Data-file part writing and concatenation are outside this PR.

Tests

Tests read the seeds directly from the new data files and compare them byte-for-byte with seeds generated from the current column values.

They cover append, full- and partial-fragment merge-insert updates, and a write_columns replacement in a fragment containing multiple data files. They also check that unindexed columns and columns with use_seeds: false do not get seeds.

🤖 Generated with Claude Code

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer bug Something isn't working labels Oct 10, 2026
@LuQQiu
LuQQiu force-pushed the lu/ent2893-seed-rewrite branch from 04558d7 to 5c433a7 Compare October 10, 2026 17:53
@LuQQiu LuQQiu changed the title fix(index): keep zone map seeds correct and present when columns are rewritten fix(index): write zone map seeds when a seeded column gets a new data file Oct 10, 2026
@LuQQiu

LuQQiu commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

Added two tests in c52ac6a for partial updates of a fragment that already has deleted rows: a merge_insert column rewrite that matches only some rows, and a write_columns replacement streamed as three batches. Both compare the stored seed byte for byte with one built from the physical column read back from the replacement file (deleted rows included, restored as nulls), and the first also asserts that the deletion-filtered scan would have produced a different seed, so the check cannot pass by accident. No change to the code under test.

@LuQQiu

LuQQiu commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

d6aff73 addresses the review's items 2 and 4.

Item 4: SeedCollector::for_write now runs before open_update_writer in write_columns and in merge_insert's column rewrite, so a failure to load the indices leaves no staged file behind.

Item 2: two tests cover the writes that the mode gate (!= Overwrite instead of == Append) newly seeds: the fragments Dataset::update rewrites and the fragments merge_insert inserts for unmatched rows (WhenNotMatched::InsertAll). Each compares the seed in every newly written data file with one built from that file's physical column. Sentence for the description, if wanted: Besides append, the fragments written by Dataset::update and by merge_insert for inserted rows now carry seeds too, since both write against the existing dataset in create mode.

Item 3 was already covered by c52ac6a. Items 1 and 5 are out of this PR's scope by design: the PR only guarantees that new data files for a seeded column carry correct seeds; it does not change how the index merge consumes them.

@LuQQiu
LuQQiu marked this pull request as ready for review October 10, 2026 18:27

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@LuQQiu

LuQQiu commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

9e2b392: the batched write_columns test now streams ten rows in four batches, so the batch edges (rows 3, 6, 9) no longer coincide with the four-row zone edges and every zone but the last spans two batches, as its comment claims. No other change.

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Oct 10, 2026
@LuQQiu

LuQQiu commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

6055aef fixes the view-input regression.

Cause. merge_insert's column rewrite and the fragment Updater handed the seed collector the caller's batch, while the data file writer converted it on its own inside write() (V2WriterAdapter::write_batch runs SchemaAdapter::to_physical_batch, which never touches the caller's batch). A Utf8View or BinaryView input for a seeded Utf8 or Binary column therefore reached ZoneMapSeedWriter as a view array and failed with Type mismatch: expected Utf8, got Utf8View.

Fix. Both consumers now receive the batch normalized once through SchemaAdapter::to_physical_batch, the same mechanism the fragment write path already used: in merge_insert's rewrite the batches are normalized where _rowaddr is dropped, so both batching branches see the same batches; in the Updater it happens in write_batch. The seed collector's type checks are untouched.

Audit of the other path. FileFragment::write_columns rejects view input in its schema check before anything is written (column data for fragment 0 does not match the requested schema: expected Binary got BinaryView), so it cannot hit the mismatch and is unchanged.

Tests. Two merge_insert full-fragment rewrites, Utf8View → Utf8 and BinaryView → Binary (the latter fed in three-row source batches that cross the four-row zone edges), both with nulls. Each verifies the written values, reads the replacement file's physical column and compares its recomputed seed byte for byte with the stored seed. On the previous head the Utf8View test failed with the type mismatch above; the BinaryView case was first written against write_columns and failed in its schema check instead, which is why it moved to merge_insert. Both pass after the fix.

@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 10, 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 10, 2026
LuQQiu and others added 5 commits October 12, 2026 13:38
… file

When a column has a ZoneMap index with write seeds enabled, every writer
that produces a new data file for that column must embed a seed built
from the values it wrote. Only the fragment append path did so; column
rewrites (merge_insert in column-rewrite mode, the fragment Updater used
by add_columns, merge and alter_columns, and FileFragment::write_columns
used by computed and function column refreshes) wrote replacement column
files without seeds.

One SeedCollector now resolves the seed writers for the columns of the
file being written and is used by all of those writers, so the data file
that serves a seeded column always carries a seed of its current values.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The expected seed is built from the physical column read back from the
replacement file, deleted rows included, rather than from a scan that
filters them out; write_columns is also driven with several batches.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…file

A failure to load the indices no longer leaves an empty staged file
behind in write_columns, and merge_insert's column rewrite follows the
same order. Tests cover the two writes the mode gate newly seeds: the
fragments rewritten by Dataset::update and the fragments merge_insert
inserts for unmatched rows.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…daries

Ten rows in three batches put the batch edges exactly on the four-row
zone edges; four batches make every zone but the last span two batches.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
merge_insert's column rewrite and the fragment Updater handed the seed
collector the caller's batch while the data file writer converted it on
its own, so a Utf8View or BinaryView input for a seeded Utf8 or Binary
column failed with a type mismatch in the seed writer. Both consumers now
receive the batch normalized once through SchemaAdapter, as the fragment
write path already did. write_columns rejects view input before writing
and is unchanged.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@LuQQiu
LuQQiu force-pushed the lu/ent2893-seed-rewrite branch from 6055aef to b7e0736 Compare October 12, 2026 20:41
@LuQQiu

LuQQiu commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main at 852c4acd3 to clear the conflict. The only conflict was the import list in rust/lance/src/dataset/write.rs: #9891 added managed_blobs_enabled next to an import of IndexMetadata that this branch had dropped (its last user moved into write/seeds.rs). Resolution keeps the new import and the shorter lance_table::format list. The five commits are otherwise unchanged. Verified on the build box: clippy with -D warnings on lance-core/lance-index/lance-table/lance, lance-index zonemap tests (40) and the lance seed/zone-map/updater tests (343) pass.

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 12, 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 rebase preserves the reviewed seed-writing behavior and the view-input fix. For seed-enabled ZoneMap columns, replacement files still carry seeds matching their physical values, including nulls and deleted-row positions. No blocking items remain.

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

@westonpace westonpace 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.

Thanks for both the enhanced test coverage and the fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-index Vector index, linalg, tokenizer bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants