Skip to content

fix(clustering): reject type changes, not renames, for new definitions - #10399

Merged
LuQQiu merged 12 commits into
lance-format:mainfrom
LuQQiu:codex/clustering-definition-key-dependency
Oct 29, 2026
Merged

LuQQiu merged 12 commits into
lance-format:mainfrom
LuQQiu:codex/clustering-definition-key-dependency

Conversation

@LuQQiu

@LuQQiu LuQQiu commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

When committing new clustering definitions, reject concurrent column type changes or deletions, but allow renames that preserve the field ID and type.

Clustering groups rows with similar column values together. An application saves two kinds of information to do this:

  • Which columns to use: for example, customer_id and event_time. Lance calls the record of their field IDs a clustering definition.
  • How to turn those values into groups: for example, how to convert timestamps into numerical coordinates and where to split the resulting coordinate space. These computed rules are called a clustering spec.

Why field IDs are not enough

A column has a name and a field ID. The name is what users write in SQL; the field ID identifies the column inside Lance. Clustering definitions use field IDs because they survive renames: customer_id can become account_id without becoming a different column.

When the first clustering definition is allocated, Lance enables its existing non-reusable field-ID protection. A rename keeps the ID, and a dropped column's ID cannot be reused for a newly added column. This prevents a definition from accidentally referring to a different column that happens to reuse the old ID.

However, a stable field ID does not freeze the column's type. The type can still change, even when the field ID stays the same.

Why clustering depends on the type

Clustering methods commonly normalize each selected column into a numerical coordinate before grouping rows. That conversion depends on the column's logical type: an integer, a string and a timestamp need different handling. For timestamps, even the unit matters: interpreting the same number as seconds or milliseconds produces different values.

A clustering spec records the rules prepared from those typed values. If those rules are saved together with a new definition, the commit must not succeed after a selected column changes type. A rename alone does not change how the values are normalized.

The race this PR prevents

Suppose an application is preparing a new definition and grouping rules for customer_id: int64:

  1. A worker reads the table and prepares rules using integer customer IDs.
  2. Another writer changes customer_id to a different type before the worker commits the new definition and rules together.
  3. This guard rejects the worker's commit instead of saving rules prepared for the old type. It also rejects a commit if the selected column was deleted.

Checking the schema before submitting the commit is not enough: another writer can change it after that check. Lance therefore checks again inside the commit path, including when retrying against a newer table version.

The scope is new definitions only. An update that only attaches rules to an already allocated definition does not get this type-change protection. To protect publication of those rules with this check, allocate a new definition and save both in the same commit.

If the other writer only renames customer_id to account_id, keeping the same field ID and type, this typed-field check allows the commit. Unrelated appends and unrelated schema changes do not invalidate these columns either. The first activation of non-reusable field IDs retains its existing stricter identity checks.

How callers use it

Callers supply the complete desired definition list through the existing API. No separate dependency list is required:

CommitBuilder::new(dataset)
    .with_clustering_definitions(desired_definitions)
    .execute(transaction) // UpdateConfig carrying the metadata to save
    .await?;

Lance automatically compares definition IDs with max_clustering_id from the transaction's original read manifest. Every ID above that allocation high-water mark is new and must be checked. The mark does not fall when old definitions are removed, and it stays fixed across commit retries.

For example, if the read mark is 10 and the submission adds 11 and 12, Lance checks every selected column in both definitions, not just 12. A type change or deletion affecting either definition rejects the entire commit; neither the new definitions nor their accompanying metadata are published.

The check includes timestamp units/time zones and nested field structure, but ignores column names. A missing or incompatible field causes a commit conflict; the caller must reload and validate its request.

New-allocation checking already exists in #10383. This PR makes its field comparison type-based rather than name-based and allows additive schema changes through the first-activation identity fence without repeated ancestry scans. Retained definitions do not become extra column-type dependencies; existing allocation/removal conflict checks remain in place.

@github-actions github-actions Bot added A-python Python bindings A-java Java bindings + JNI A-namespace Namespace impls bug Something isn't working labels Oct 28, 2026
@LuQQiu

LuQQiu commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

1 similar comment
@LuQQiu

LuQQiu commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Still open from earlier reviews (1):

  • Unresolved: 1 minor or pre-existing.

@LuQQiu

LuQQiu commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

@LuQQiu

LuQQiu commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

@LuQQiu
LuQQiu changed the base branch from main to codex/clustering-runtime-main October 28, 2026 16:05
LuQQiu and others added 4 commits October 28, 2026 10:32
…ields

`refuse_key_fields_that_changed_identity` checked only the definitions a
list allocates. A writer that carries a retained definition plans whatever
it publishes alongside the list (metadata derived from the keys, a removal)
against the key fields as it read them, so a key renamed, retyped or
re-parented between its read snapshot and the landing manifest invalidates
that plan just as it would an allocation. Every listed definition's key
fields must now keep their identity; the refusal is the same commit
conflict, and unrelated appends and metadata writes still rebase.

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

A retained definition whose key is dropped between the writer's read and the
landing manifest is refused like a rename or a cast, while a key that was
already absent when the writer read the table is history: such a list still
lands, allocates and removes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…key as a conflict

A key field's identity is its path of names and logical types from the
root, so renaming a nested key's parent struct is a change while metadata
or nullability edits below it are not. A key the writer read that the
landing schema no longer has is a changed dependency for every listed
definition, new or retained, and refuses as the same commit conflict; a key
the writer's own snapshot already lacked stays history. The Merge fence
uses the same identity.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Comparing only the path to a key let a struct key's child be retyped,
renamed, added or removed under a carried list, since a struct's logical
type names no children. The identity now also compares every descendant's
id, name and logical type in order, while metadata and nullability edits
anywhere still rebase, and a primitive key inside a struct still does not
depend on its siblings. The Merge fence shares the helper.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@LuQQiu
LuQQiu force-pushed the codex/clustering-definition-key-dependency branch from 134a58d to 2a444d1 Compare October 28, 2026 17:33
@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer A-deps Dependency updates A-encoding Encoding, IO, file reader/writer A-format On-disk format: protos and format spec docs A-docs Documentation A-ci CI / build workflows format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). labels Oct 28, 2026
@LuQQiu
LuQQiu changed the base branch from codex/clustering-runtime-main to main October 28, 2026 17:34
@LuQQiu

LuQQiu commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

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

Code review found no issues

No high-confidence issues detected in this change.

Still open from earlier reviews (1):

  • Unresolved: 1 minor or pre-existing.

…dependency

Brings the test-fixture initializers from lance-format#10427 and the compaction changes
from lance-format#10440; the key-dependency change touches none of those files.

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

The previous commit added the rewritten doc without removing the old block
above it, leaving two descriptions; only the current one stays.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@LuQQiu

LuQQiu commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

14c8065: the previous doc commit left the superseded rustdoc block in place above the new one; removed. Documentation only.

@LuQQiu

LuQQiu commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

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

Code review found no issues

No high-confidence issues detected in this change.

Still open from earlier reviews (2):

  • Unresolved: 2 minor or pre-existing.

…ce, and lets additive merges through

`keeps_every_field_identity` compared every read field by walking both
schemas' ancestries and equating whole subtrees, so a concurrent Merge that
only added a child under a struct was refused although added fields are meant
to be fine, and the walk allocated quadratically on wide schemas. It now
builds one map of the landing fields and checks each read field shallowly:
same name, logical type and parent under its id. Every read field is visited,
so a parent's identity covers the path above it and a child's the shape below;
a renamed, retyped, moved or missing read field is still refused.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@LuQQiu

LuQQiu commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment thread rust/lance/src/dataset/write/commit.rs Resolved
…ile is written

An id in the dependency list that the definitions list does not hold was
refused inside the manifest build, after the transaction file had been
written, leaving an orphan file behind. The builder now refuses it beside its
existing precheck, before any I/O; the build-time check stays as the
authority. A unit test pins the first-activation fence's contract on a struct
the writer read: an added child is compatible, a renamed, retyped, missing or
moved child is not.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@LuQQiu

LuQQiu commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

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

Code review found no issues

No high-confidence issues detected in this change.

@LuQQiu
LuQQiu marked this pull request as ready for review October 29, 2026 15:53

@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 changed the title fix(clustering): a definitions list is a read dependency on its key fields fix(clustering): prevent publishing clustering metadata after column type changes Oct 29, 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 29, 2026
…pendencies

Drop CommitBuilder::with_clustering_dependencies and its ManifestWriteConfig /
ManifestBuildConfig plumbing. The commit already carries the read manifest
and the complete desired list, so the definitions it allocates are the ones
whose id lies above the read manifest's max_clustering_id; every one of them
is checked against the landing schema from the read schema (field id and
logical type along the path and typed subtree), not only the highest, and a
failure in any refuses the whole commit. The mark is the read snapshot's and
stays fixed across rebase attempts; retained definitions are not
prerequisites, and the allocator and first-activation fence are unchanged.

Tests cover two allocations in one submission with a retype or drop on the
lower id, the allocation mark versus the largest present id, same-id rename,
timestamp unit/timezone, retained keys changing under an unrelated
submission, and re-planning from the landing snapshot.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@LuQQiu

LuQQiu commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 29, 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 Oct 29, 2026

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

Code review completed

Nothing new to post: everything this review found is already covered by existing comments on this pull request or didn't merit a separate one.

@LuQQiu LuQQiu changed the title fix(clustering): prevent publishing clustering metadata after column type changes fix(clustering): reject type changes, not renames, for new definitions Oct 29, 2026
@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 29, 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 with a non-blocking risk.

The updated PR description and example now match the allocation-only guard; the earlier documentation request is addressed.

A later spec update for a retained definition can still publish after a key type change. To use this guard for spec publication, allocate a fresh definition and publish the spec in the same commit.

The allocation-key and manifest-build tests passed locally. Dataset integration tests remain unverified locally.

Please mark this PR with the breaking-change label.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 29, 2026
@LuQQiu
LuQQiu merged commit ca3d16d into lance-format:main Oct 29, 2026
46 of 49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ci CI / build workflows A-deps Dependency updates A-docs Documentation A-encoding Encoding, IO, file reader/writer A-format On-disk format: protos and format spec docs A-index Vector index, linalg, tokenizer A-java Java bindings + JNI A-namespace Namespace impls A-python Python bindings bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants