Skip to content

feat: add order to primary key#5683

Merged
jackye1995 merged 10 commits intolance-format:mainfrom
touch-of-grey:pk-order
Jan 11, 2026
Merged

feat: add order to primary key#5683
jackye1995 merged 10 commits intolance-format:mainfrom
touch-of-grey:pk-order

Conversation

@touch-of-grey
Copy link
Copy Markdown
Contributor

This PR adds ordering to primary key so that it can be used for btree index. This is a part of the work to make the MemTable proposal work after discussion with @jackye1995, and for my use case the primary key has to be multiple. @jackye1995 could you take a look?

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


</details>

### Unenforced Primary Key
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.

thanks for adding this! I missed it in the doc refresh

Comment thread protos/file.proto
Comment thread rust/lance-core/src/datatypes/field.rs
Address review feedback to use field_id instead of position for
consistency with other specs like partitioning and region specs.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment thread docs/src/format/table/index.md Outdated
Comment thread docs/src/format/table/index.md
Comment thread rust/lance-core/src/datatypes/field.rs Outdated
Comment thread rust/lance-core/src/datatypes/schema.rs
- Add note that primary key is fixed after initial setting
- Change "column ordering" to "primary key field ordering" in docs
- Simplify inline comments
- Update test comments to match doc terminology

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment thread rust/lance-core/src/datatypes/schema.rs Outdated
touch-of-grey and others added 2 commits January 10, 2026 19:56
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@touch-of-grey touch-of-grey changed the title Add order to primary key feat: add order to primary key Jan 11, 2026
@github-actions github-actions Bot added the enhancement New feature or request label Jan 11, 2026
Copy link
Copy Markdown
Contributor

@jackye1995 jackye1995 left a comment

Choose a reason for hiding this comment

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

looks good to me! pending CI

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 11, 2026

Codecov Report

❌ Patch coverage is 98.33333% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance-core/src/datatypes/field.rs 94.11% 0 Missing and 1 partial ⚠️
rust/lance-file/src/datatypes.rs 85.71% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread docs/src/format/table/index.md Outdated
To mark a field as part of the primary key, add the following metadata to the Arrow field:

- `lance-schema:unenforced-primary-key`: Set to `true`, `1`, or `yes` (case-insensitive) to indicate the field is part of the primary key.
- `lance-schema:unenforced-primary-key:field-id` (optional): A 1-based integer specifying the primary key field id within a composite primary key.
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.

Sorry for the back and forth, but I think I agree now that position is better than field-id. For partition and region spec, they represent new fields in the spec so spec makes sense. But here it is pretty confusing to have field ID and primary key field ID in the same place. Let's move back to that.

touch-of-grey and others added 4 commits January 11, 2026 11:39
Address review feedback to avoid confusion between "schema field id"
and "primary key field id" by using "position" terminology instead.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use is_unenforced_primary_key() method instead of the removed
unenforced_primary_key field.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the java label Jan 11, 2026
- Java: Add unenforcedPrimaryKeyPosition field and getter to LanceField
- Python: Add is_unenforced_primary_key() and unenforced_primary_key_position()
  methods to LanceField

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jackye1995 jackye1995 merged commit d1ec03c into lance-format:main Jan 11, 2026
25 of 29 checks passed
@touch-of-grey touch-of-grey deleted the pk-order branch January 11, 2026 21:25
jackye1995 pushed a commit to jackye1995/lance that referenced this pull request Jan 21, 2026
This PR adds ordering to primary key so that it can be used for btree
index. This is a part of the work to make the MemTable proposal work
after discussion with @jackye1995, and for my use case the primary key
has to be multiple.

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request java python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants