Repository navigation
docs(format): allow variable-length zones in version 1 write seeds - #10155
Conversation
|
Important Format specification voteThis PR modifies the Lance format specification, so it requires 3 binding +1 votes from PMC members (excluding the proposer), at least one of them on the latest commit, and a minimum 72-hour voting period, weekends excluded, before it can merge. Vote by approving this PR (+1) or requesting changes (−1, a veto). See the voting process. Approvals carry over across pushes, so a rebase or a typo fix does not send everyone back to re-vote. Whoever approves the latest commit is vouching that nothing substantive has changed since the earlier approvals; if something has, ask for fresh votes. Status: ❌ Blocked — 0 of 3 required approvals
Updated automatically by the format-spec vote gate, which re-checks every 15 minutes — just voted? Re-check now (press Run workflow; leave the input blank to re-check every open format PR). A PMC member may apply the |
There was a problem hiding this comment.
✅ Gate recommendation: approve.
Using the existing zone_length values is sufficient to preserve short source-file zones during binary-copy compaction without adding another offset field. The revised rule stays within the unimplemented version 1 contract and retains its capability-gated activation.
Teaches binary-copy compaction to preserve zone write seeds without decoding or rescanning any column data, and makes seed readers locate zones by their lengths. Stacked on the version 1 seed implementation. No format change: the variable-length zone layout is the version 1 format as documented by #10155; locator encoding, schema fields, version metadata, capability flags and the null bitmap encoding are unchanged. Readers locate zones by length: - Zone i starts at the checked cumulative sum of the earlier zone_length values instead of i * rows_per_zone, so a zone shorter (or, after concatenating sources collected at other granularities, longer) than rows_per_zone may appear anywhere. rows_per_zone in the locator stays the writer's collection configuration. Zero-length zones are rejected, and a seed harvested for an index update must cover exactly the fragment's physical rows (FragmentSeed.physical_rows). Binary-copy carrying, per output file and per column, in copy order (outputs flush only at source-file boundaries, a premise pinned by a test): - All inputs carry complete version 1 seeds for the column: their zone records concatenate verbatim, whatever their collection granularities; the output locator declares the column's current rows_per_zone from the index specification (the writer default without a ZoneMap index). A single-source output carries its input's seed byte for byte. Null bitmaps shift by each source's cumulative row offset and union, with checked arithmetic; any source without a bitmap leaves the output without one. - An input without the column's seed drops the output column's seed (partial statistics never impersonate complete coverage); other columns keep theirs, and missing statistics never force the data onto the re-encoding path. - Version 0 or mixed sources drop the column: no implicit conversion. Unknown versions keep the refusal contract, and corrupt statistics refuse binary copy instead of posing as missing seeds. - The gate admits extra global buffers only when each is claimed by a parseable seed locator whose payload validates as a zone map seed covering exactly the file's rows; unrecognized extra buffers keep the existing rejection. Columns match by field id and output keys use current names. - Outputs embed fresh buffers under newly assigned indexes, and the task reports wrote_v1_seeds truthfully through the existing commit pipeline, so the paired FLAG_ZONE_WRITE_SEEDS bits follow the published files. Co-Authored-By: Claude Fable 5.1 <[email protected]>
jackye1995
left a comment
There was a problem hiding this comment.
this is just clarification, no need for format vote
## Summary Zone write seeds are per-column statistics embedded in data files, collected while those files are written. A later index update can reuse them instead of reading the column again. This PR implements the V1 seed format defined in #9564 and #10155, fixes NaN-aware ZoneMap pruning, and preserves compatible seeds during binary-copy compaction. **Breaking compatibility:** this PR automatically activates new reader and writer feature flags on tables with seed-enabled indices. Clients that do not support `FLAG_ZONE_WRITE_SEEDS` can no longer read or write the resulting snapshots. This can happen with default ZoneMap options, not just an explicit `use_seeds: true`. ## 1. What was wrong with NaN handling? Arrow Rust's floating-point total order distinguishes the two NaN signs: ```text negative NaNs < -Infinity < ordinary finite values < +Infinity < positive NaNs ``` Previously, statistics counted both signs together and wrote `max = +NaN` whenever any NaN was present. This hid the ordinary maximum and did not say whether negative NaNs existed. Query evaluation also mishandled some NaN-only zones and predicates with NaN bounds. Examples of incorrect pruning addressed here: | Zone contents | Query | What went wrong | | --- | --- | --- | | Only negative NaNs | `x < 0` | Could discard the zone even though negative NaNs match under Arrow Rust ordering. | | Only positive NaNs | `x > 100` | Could treat the lack of ordinary bounds as an empty zone, dropping matching positive NaNs. | | Ordinary values and NaNs | Range with a NaN literal as a bound | Could short-circuit on `nan_count` and drop ordinary values that satisfy the range. | The PR changes both the statistics written into new seeds and the evaluation of existing index files. These are separate changes: the ZoneMap index file schema remains unchanged. ## 2. V1 seeds keep NaNs out of both `min` and `max` | Field | Meaning in a V1 seed | | --- | --- | | `min`, `max` | Bounds on non-null, non-NaN values, following Arrow Rust ordering. Infinities are included. Types without supported value bounds retain typed-null bounds. | | `null_count` | Exact number of null physical rows. For nested types this counts parent nulls, not null elements inside a non-null value. | | `nan_count` | Total number of NaNs, of either sign. | | `negative_nan_count` | Number of NaNs with the sign bit set. Positive NaNs = `nan_count - negative_nan_count`. | | `zone_length` | Number of physical rows summarized by the record, serialized as `UInt64`. | **Positive NaNs no longer replace the ordinary `max` in V1 seeds**, and negative NaNs no longer produce a positive-NaN marker either: | Values | Previous seed bounds | V1 seed bounds | V1 NaN counts | | --- | --- | --- | --- | | `1, 5, +NaN` | `min = 1`, `max = +NaN` | `min = 1`, `max = 5` | total = 1, negative = 0 | | `1, 5, -NaN` | `min = 1`, `max = +NaN` | `min = 1`, `max = 5` | total = 1, negative = 1 | | `1, 5, -NaN, +NaN, null` | `min = 1`, `max = +NaN` | `min = 1`, `max = 5` | total = 2, negative = 1; nulls = 1 | The shared statistics accumulator collects the negative count in its existing NaN pass. The seed writer saves the new column and adds `version = "1"` to the seed buffer's IPC schema metadata. - No version metadata means V0. Its NaN sign split is **unknown**, not zero. The decoder checks the version before interpreting bitmap metadata or statistics. - The optional `seed_null_bitmap` retains its encoding; run optimization reduces its size for contiguous nulls. - The data-file locator remains `lance.seed.<column_name> = <buffer_index>:<rows_per_zone>`. - The default zone size remains 8192 rows; configured zone sizes are unchanged. - Readers derive zone starts by summing `zone_length`, allowing short zones within concatenated seeds. - Harvesting verifies complete physical-row coverage before using the seed instead of a column scan. ### Unsupported seed versions: behavior depends on the consumer This writer emits V1. It does not negotiate an arbitrary requested output version, and it does not read old files' seeds before appending new data. A file with an unsupported seed therefore does not, by itself, prevent a later V1 append. | Consumer | Unsupported seed version, such as V2 | | --- | --- | | Seed decoder | Returns `NotSupported` before interpreting bitmap metadata or statistics. It never assumes V0/V1 from matching column names. | | ZoneMap index update | Propagates the error and fails that index update without publishing new index coverage. **It does not automatically fall back to scanning for an unsupported version.** Existing scan fallback for missing seeds or declined configuration remains unchanged. | | Binary-copy compaction | Continues copying data but omits the affected output column's seed, including both its buffer and locator. Other columns can still carry compatible seeds. | Adding a graceful scan fallback for unsupported versions in the ZoneMap index consumer is outside this PR's scope. The current error is a maintenance limitation, not permission to interpret unknown statistics or mark an uncovered fragment as covered. ## 3. Query pruning handles ordinary values and both NaN signs The evaluator checks whether ordinary values, negative NaNs, or positive NaNs could satisfy the **whole predicate**. It excludes a zone only if none can match. Unknown signs or NaN payloads are handled conservatively. This fixes the examples above, including bounded ranges where different NaN signs might separately satisfy opposite bounds but neither satisfies the whole range. `column_value_range` returns unknown for NaN-bearing zones instead of advertising an unsafe global range. The PR also fixes evaluation of remapped legacy zones: inherited null/NaN counts can outlive some rows, so they must not override available bounds and incorrectly prove that no ordinary values remain. ### The ZoneMap index file format is unchanged **V1 applies to data-file write seeds, not to a new ZoneMap index file version.** When serializing a ZoneMap index, the writer still emits the legacy `max = +NaN` marker for any NaN-bearing zone. Its persisted schema has no `negative_nan_count`; reopening it yields an unknown sign split. The reader fixes make existing index files safe to evaluate, but persisted ZoneMap indices do not yet retain V1's more precise ordinary maximum and sign split. That limitation remains even when an index update harvests V1 seeds. ## 4. Compatibility activation and changes to the commit path V1 requires `FLAG_ZONE_WRITE_SEEDS` (`1 << 16`) in **both** `reader_feature_flags` and `writer_feature_flags`. This PR changes the previously reserved capability to supported. The fence matters because an old consumer could interpret V1's ordinary `max = 5` as proof that `x > 100` cannot match, ignoring a positive NaN in that zone. Supporting readers must understand the separate NaN counts before consuming V1 statistics. This is the transition from unversioned seeds to version-aware consumers. Future optional seed-format revisions are intended to use per-buffer version checks rather than additional table feature flags. An unsupported seed is never interpreted; each consumer rejects it or treats it as unavailable as described above. This does not promise that an older client can maintain every future index format or transparently harvest every future seed version. ### When does a table become incompatible with older clients? | Situation | Behavior | | --- | --- | | Create a seed-enabled index with this build | The index-creation commit sets both flags. Subsequent writes can emit V1 seeds. Unsupported older clients cannot access the flagged snapshot, even before a V1 seed is written. | | Legacy table with a seed-enabled index but no flags | A subsequent non-Restore commit retaining that index activates both flags. This is not restricted to appends. A write prepared before activation omits seeds; later writes from a flagged snapshot emit V1. | | Existing V0 data files | Remain unchanged and readable by the new implementation. Activation does not scan, rewrite, or backfill them. | | Later index drop, overwrite, or restore after activation | Capability bits remain sticky; these operations do not make the table compatible with older clients again. | **There is no new explicit upgrade API or opt-in setting.** Existing per-index `use_seeds` settings still select collection. Their defaults are unchanged, but some types—including strings, binary, and decimals—already default to enabled. Creating a ZoneMap index on a string column with default options therefore activates the new capability. Collection is not enabled for every column or for tables without a requesting index. ### What changes outside seed encoding? - `IndexSeedWriter::required_feature_flags()` lets each writer declare its requirements; the default is zero, and the ZoneMap writer requests bit 16. - The shared `SeedCollector` allows a flagged writer only when the writer's snapshot already has its required reader and writer bits. - Ordinary and detached commit paths in `io/commit.rs` call `apply_seed_feature_flags` on the candidate manifest and prepared index list. It selects seed writers and adds their requirements. It does **not** inspect data-file footers. Commits with indices still run this selection after activation; legacy indices without inline details can require session-cached index-metadata lookups. There is **no change to `dataset/write/commit.rs` or `lance-table/src/transaction/builder.rs`**, no seed-specific transaction field, no transaction proto change, and no process-local file ledger. Generic detached/batch commit validation was removed as outside this PR's scope. Arbitrary external file imports are not automatically inspected; low-level callers remain responsible for meeting the destination table's capability requirements. This PR also does not add protection for publishing files through a detached base older than, or unrelated to, their writing snapshot. ## 5. Binary-copy compaction carries compatible V1 seeds Previously, extra global buffers—including seed buffers—made a file ineligible for binary-copy compaction. This PR recognizes and validates seed buffers so compatible files can use that path. For each output column, it validates input seeds and physical coverage, resolves column identity through the file's physical-column mapping, concatenates compatible V1 records in copy order, shifts null bitmap offsets, and writes a new buffer and locator. Renamed or remapped fields are matched through that mapping rather than assuming their stored field IDs still apply. No column rescan, statistics recomputation, or zone rechunking is performed. Every contributing input must have complete, compatible V1 statistics for a column's seed to be carried. Missing, V0, mixed-version, or unsupported-version seeds leave that output column without a seed while data still binary-copies. Same-version V1 records are concatenated and remain V1; unknown versions are never relabeled. No actual V2 implementation is added. Unrelated unknown global buffers, corrupt supported seeds, invalid locators, and unverifiable physical-column mappings still disqualify binary copy. These are distinct from a recognized optional seed declaring an unsupported version. Debug messages distinguish an omitted column seed from a genuinely disabled binary-copy path. This adds seed-buffer reads during eligibility checking and execution, plus an index-configuration lookup for output zone-size metadata. It is not a zero-I/O change. V0 seeded files may now binary-copy without retaining their optional seeds, rather than fall back to re-encoding; later normal index maintenance can still scan when seeds are unavailable. ## API and scope - Adds the seed-writer capability method, signed NaN statistics, and seed parsing/merging helpers for binary copy. - Adds public struct fields to `Statistics` and `FragmentSeed`; downstream struct-literal constructors need updating. - Does not change the transaction wire format, implement fragment column statistics, or add index-update-on-write maintenance. - Does not change the ZoneMap index file schema or extend its existing scan fallback policy to unsupported seed versions. - Does not change generic detached/batch commit acceptance rules. - The `scanner.rs` diff adds regression tests, not new scanner runtime behavior. ## Tests and validation Coverage includes V0/V1 decoding, unknown versions, invalid counts, physical coverage, both NaN signs and payloads, NaN range bounds, indexed-versus-unindexed results, legacy remapped zones, activation and sticky flags, retries, serialized/batched/detached commits, and binary-copy preservation with renamed/remapped fields. The future-version tests additionally verify: - A V2 seed with a different bitmap encoding is rejected by version before the bitmap is decoded. - Forced binary copy succeeds with mixed/unsupported or missing seeds, omits only the affected column's seed, and preserves another column's V1 seed. - Carried V1 null bitmap offsets agree with the output data. - A ZoneMap update encountering V2 returns `NotSupported` and leaves the committed dataset version and index coverage unchanged; uncovered data remains queryable. - Appending beside an unchanged V2-seeded file produces V1 seeds without extra file requests in the tested setup. Latest implementation verification on head `9b6bee8c8`: - Formatting and clippy with `-D warnings` passed for the affected crates. - 18 CommitBuilder tests passed. - 127 related seed, version, commit-I/O, binary-copy, and collector tests passed. The request-count test covers append, update, and merge-insert with inline index details. It does not establish zero additional metadata I/O for cold legacy indices without inline details, nor is it a commit-latency benchmark. Broader suite and platform results are reported by the PR's CI checks; the local validation above is targeted, not a full-suite run. --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
Summary
Allow zones of different lengths in version 1 write seeds. Each zone covers
zone_lengthphysical rows, and together the zones cover the file's column data in order, without gaps or overlaps.This lets binary-copy compaction preserve existing seed records, including short zones at source-file boundaries.
Only one paragraph in the format document changes (2 lines added, 4 removed).
rows_per_zoneand its locator encoding stay unchanged. No schema fields, version numbers, capability flags, or runtime code change.Readers must use
zone_lengthto locate zones; implementation follows separately.Format review
Requesting a PMC format-vote waiver for this limited correction to the unreleased V1 layout constraint.
Validation
cd docs && uv run mkdocs build(existing external-documentation link warnings).git diff --checkpassed.