Skip to content

feat(index): change JSON scalar index to row-address domain - #9856

Merged
westonpace merged 6 commits into
mainfrom
claude/jolly-brown-yfwjsi
Nov 6, 2026
Merged

westonpace merged 6 commits into
mainfrom
claude/jolly-brown-yfwjsi

Conversation

@westonpace

@westonpace westonpace commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Similar to #9814 (Bitmap/LabelList → row-address domain), and #9481 (BTree). It applies the same migration to the JSON index. JSON is a wrapper, so it takes its domain from the target index it wraps. This is also built on #9721 which adds the target index version to the JSON index details.

Prior to this change we only supported creating JSON indexes against targets that were in their "legacy domain". For example, a JSON->BTREE index would be row ids and a JSON->ZONE_MAP index would be row addrs. This remains the behavior for JSON index version 0.

This PR adds a new JSON index version (1) which can only be used with row address domain indcies. The new index version is really just simplification and convenience as it makes it easy to tell we are in the row address domain without consulting the index details and doing some complicated type-dependent logic (we could otherwise determine this from the target version and index type). However, it is also consistent with the other indexes which have been bumping the index version as part of the switch.

The actual index itself did not need to change (it's just a wrapper) but some of the index management logic did (since JSON indexes could now potentially be row address indexes).

@github-actions github-actions Bot added A-python Python bindings A-index Vector index, linalg, tokenizer A-format On-disk format: protos and format spec docs format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). enhancement New feature or request labels Oct 9, 2026
@westonpace
westonpace force-pushed the feat/bitmap-to-row-addresses branch 5 times, most recently from cf543a7 to 350daad Compare October 15, 2026 13:15
@westonpace
westonpace force-pushed the claude/jolly-brown-yfwjsi branch from f1300b9 to 722bae5 Compare October 19, 2026 16:50
@westonpace
westonpace force-pushed the feat/bitmap-to-row-addresses branch from 64ed39c to 52ca5df Compare October 22, 2026 13:29
Base automatically changed from feat/bitmap-to-row-addresses to main October 23, 2026 22:03
@westonpace
westonpace force-pushed the claude/jolly-brown-yfwjsi branch from 722bae5 to ac48364 Compare November 2, 2026 20:19
westonpace and others added 2 commits November 3, 2026 09:19
Stacked on #9481 (BTree) and #9814 (Bitmap/LabelList). Completes the
row-address-domain migration for the JSON scalar index: a JSON index
now records its wrapped target's own persisted version
(JsonIndexDetails::target_index_version) and is itself stamped with
format version 1 (JSON_ROW_ADDR_DOMAIN_VERSION) exactly when that
target stores physical row addresses, so IndexMetadata::results_are_row_addrs
and the optimize-time domain guards can see through the wrapper without
decoding the nested target details.

- lance-table/format/index.rs: extend index_details_are_row_addrs with
  a JSON case gated on the wrapper's own version.
- lance-index/scalar/json.rs: track target domain through
  create/update/remap, relabel to row-id domain on a dataset without
  stable row ids (mirroring BTree/Bitmap/LabelList), and fall back to
  the pre-migration version when loading details written before
  target_index_version existed.
- lance/index/{append,scalar}.rs: remove the now-unneeded guard that
  rejected a JSON-wrapped BTree/Bitmap/LabelList index on a
  stable-row-id dataset, and extend the merge/rebuild domain-safety
  checks to recognize a JSON-wrapped migrated target.
- Tests covering the new behavior end to end, plus a Python
  upgrade/downgrade compat test.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@westonpace
westonpace force-pushed the claude/jolly-brown-yfwjsi branch from ac48364 to ba0f4ff Compare November 3, 2026 17:37
@westonpace
westonpace marked this pull request as ready for review November 3, 2026 17:38

@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 repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Important

Format specification vote

This 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

Approvals none (0/3)
Latest commit approved by none — one PMC member must approve the latest commit
Vetoes none
Voting period ends Fri 2026-11-06 17:38 UTC (09:38 PST)

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 format-waived label to waive the vote for a trivial edit (typo, wording, formatting).

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

For stable-row-ID workloads that compact data, run index optimization after compaction to restore JSON index coverage. Queries remain correct during the fallback, at the cost of a full scan.

// (`lance_index::scalar::json::JSON_ROW_ADDR_DOMAIN_VERSION`) exactly
// when that target stores row addresses, so the wrapper's own version
// answers this without decoding the nested target details.
let is_json_addr_domain = details.type_url.ends_with("JsonIndexDetails") && index_version >= 1;

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.

Compaction drops JSON→BTree coverage on stable-row-ID datasets, so indexed lookups fall back to full scans. The new address-domain classification prevents these segments from following stable IDs, while supports_eager_remap() still recognizes only plain BTree/Bitmap/LabelList segments and skips the wrapper. Including JSON wrappers with remappable targets in eager-remap selection would preserve coverage.

I verified that compaction reduces indexed coverage from 12 rows to zero, queries remain correct, and optimize_indices() restores all 12 rows. This is a recoverable performance risk.

Reproducer

Run with the current build. The final assertion fails with compaction left 0 indexed rows; the query and recovery assertions pass.

import tempfile
import lance
import pyarrow as pa
from lance.indices import IndexConfig

with tempfile.TemporaryDirectory() as path:
    ds = lance.write_dataset(
        pa.table({"json": pa.array([f'{{"val": {i}}}' for i in range(12)], pa.json_())}),
        path, max_rows_per_file=4, enable_stable_row_ids=True,
    )
    ds.create_scalar_index(
        "json", IndexConfig(index_type="json", parameters={
            "target_index_type": "btree", "path": "val",
        }), name="json_idx",
    )
    assert ds.stats.index_stats("json_idx")["num_indexed_rows"] == 12
    ds.optimize.compact_files()
    after = ds.stats.index_stats("json_idx")["num_indexed_rows"]
    assert ds.to_table(filter="json_get_int(json, 'val') == 9").num_rows == 1
    ds.optimize.optimize_indices()
    assert ds.stats.index_stats("json_idx")["num_indexed_rows"] == 12
    assert after == 12, f"compaction left {after} indexed rows"

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 3, 2026
@westonpace westonpace removed the format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). label Nov 3, 2026
- rust/lance-index/src/scalar/json.rs: fix rustdoc error by removing an
  intra-doc link from a public constant's doc comment to the private
  `legacy_target_index_version` function (rustdoc rejects public docs
  linking to private items under -D warnings).

- python/python/tests/compat/test_scalar_indices.py: fence old-writer
  inserts/updates in JsonRowAddressDomainIndex.check_write, matching the
  existing BTree/Bitmap/LabelList row-address-domain compat tests. Skip
  the upgrade/downgrade direction for Lance 14.x, whose writer outright
  rejected creating a JSON-wrapped BTREE index on a stable-row-id dataset
  (the restriction this PR lifts), so no 14.x build can produce that
  test's fixture.

- python/python/tests/compat/compat_decorator.py: add a
  skip_upgrade_downgrade hook so a compat test can opt out of the
  old-build-creates round trip when a release could not produce the
  fixture at all.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y3hhWhSHTx2oyYLdd2aDFt
@lance-gatekeeper lance-gatekeeper Bot removed K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 3, 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 Nov 3, 2026

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

One blocking issue having to do with Zone Maps.

Otherwise, just hoping for a future refactor to make lance-index and lance-table better decoupled 😄

/// See [`IndexMetadata::results_are_row_addrs`]. Exposed separately so a wrapper
/// index (e.g. JSON) can classify the target index it holds, which has details and
/// a version but no [`IndexMetadata`] of its own.
pub fn index_details_are_row_addrs(details: &prost_types::Any, index_version: i32) -> bool {

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.

suggestion: in the future, could this be answered by a method ScalarIndexPlugin::result_domain(details, index_version)? This is very tightly coupled with the indexes that exist in our crates. And in face, lance-table isn't supposed to know about the details of lance-index; since lance-index is a dependent of lance-table. This can be a refactor in a future PR.

Here's a suggested path, that accounts for crate boundaries.

In lance-table, define:

pub enum ResultDomain { RowIds, RowAddrs }

pub trait IndexDomains: Send + Sync + Debug {
    /// `None` when nothing in this build recognizes the segment.
    fn result_domain(&self, index: &IndexMetadata) -> Option<ResultDomain>;
    fn can_remap(&self, index: &IndexMetadata) -> bool;
}

In lance-index, define:

trait ScalarIndexPlugin {
    /// Metadata only: never opens index files.
    fn result_domain(&self, details: &Any, index_version: u32) -> Result<ResultDomain>;
}

The SCALAR_INDEX_PLUGIN_REGISTRY will impl IndexDomains, and be passed via ManifestBuildConfig.

Then IndexMetadata::results_are_row_addrs() would instead be domains.result_domain(&index) == Some(ResultDomain::RowAddrs). Similar checks for can_follow_stable_row_ids() and supports_eager_remap().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In the future I think the rule is that all indexes will be row address indexes. So my hope is that lance-table needs this (not so small) list of "exceptions" but that it never grows over time.

If we decide we want to allow row id indexes again in the future for some reason then I agree we will need plugin methods.

@wjones127 wjones127 Nov 6, 2026 •

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.

Got it. That makes sense. I'm good with this as long as it doesn't grow after this refactor.

/// domain. Mirrors the plain BTree/Bitmap/LabelList relabeling in
/// `build_scalar_index`, and keeps such segments readable by builds that
/// predate [`JSON_ROW_ADDR_DOMAIN_VERSION`].
pub fn relabel_as_row_id_domain(created: &mut CreatedIndex) -> Result<()> {

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.

suggestion(non-blocking): it would be cool if we told the trainer up front what the domain was so we don't have to correct it later. Possibly less error prone.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm, I'll probably pass on this one. I'd like to avoid modifying the basic trainer trait at the moment.

target_details: &prost_types::Any,
target_index_version: u32,
) -> u32 {
if lance_table::format::index_details_are_row_addrs(target_details, target_index_version as i32)

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.

issue(blocking): this bumps a JSON segment over ZoneMap (or BloomFilter) to v1 too, since those targets already store row addresses. But an existing JSON-over-ZoneMap segment is v0, and results_are_row_addrs() reports it as row ids. So the two versions now disagree on domain for what is the same on-disk data.

I haven't run it, but tracing the code I think this breaks a commit:

  1. Stable-row-id dataset with a v0 JSON-over-ZoneMap segment written by an older build (the old guard in build_scalar_index only rejected BTree/Bitmap/LabelList targets, so these exist).
  2. Append rows, then optimize_indices(&OptimizeOptions::append()).
  3. The new delta segment is v1. The old v0 segment isn't forced into the rebuild, because migrated_to_row_addrs only matches BTree/Bitmap/LabelList targets.
  4. The mixed-domain check in manifest_build.rs (first.results_are_row_addrs() != index.results_are_row_addrs()) rejects the commit with "mixes row-ID and row-address segments".

Suggested fix: only bump when the target is a type whose format actually changed, i.e. legacy_target_index_version(target_details).is_some() and the target is at its address version. ZoneMap/BloomFilter targets stay v0, as they were. A test in the style of test_optimize_rebuilds_legacy_json_btree_segment_with_stable_row_ids, but over a ZoneMap target, would cover it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm, I guess that was actually a bit of a bug / shortcoming in IndexMetadata::results_are_row_addrs. We now rewrite those indexes properly.

A fresh JSON segment over a ZoneMap, BloomFilter, or FM target is stamped
with the row-address wrapper version, but an existing version-0 segment of
the same index is classified as row ids. Append-mode optimize left the old
segment in place beside the new one, and the commit was rejected for mixing
row-ID and row-address segments.

Treat every JSON index whose fresh segments are address-domain as a
migrated type, so legacy version-0 segments are folded into the rebuild.
Extend the legacy JSON rebuild test to cover a ZoneMap target.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y3hhWiuvtpwi6tePN8Fjue
@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Nov 6, 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 Nov 6, 2026
…ddress change

- Load a legacy JSON target's version via `legacy_target_index_version`
  and drop the equivalent name-keyed `legacy_row_id_domain_version`.
- Deprecate `json_wrapped_target_type`, which no longer has callers.
- Collapse the JSON test training helpers into `train_json_index`
  (returns `CreatedIndex`) plus `train_and_load_json_index`.
- Fold the JSON-over-ZoneMap stable-row-id test into the BTree
  row-address-domain test as an rstest case.
- Remove `test_json_wrapped_create_with_stable_row_ids`, now covered by
  the dataset-level row-address-domain test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y3hhWja2MjxBvXTMTQf18r
JSON-wrapped ZoneMap does not support `optimize_indices` (its target does
not report a training data type), so it cannot share the BTree test's
delete/append/optimize flow. Keep it as its own create-and-query test,
reusing the shared stable-row-id dataset and params helpers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y3hhWja2MjxBvXTMTQf18r
@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Nov 6, 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 legacy ZoneMap append failure is addressed by rebuilding version 0 JSON segments before adding address-domain data.

For stable-row-ID workloads that compact data, optimize JSON indexes afterward to restore coverage. The compaction coverage loss remains a recoverable performance risk: queries fall back to full scans while preserving results.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 6, 2026
@westonpace
westonpace merged commit 672dfdd into main Nov 6, 2026
42 of 44 checks passed
@westonpace
westonpace deleted the claude/jolly-brown-yfwjsi branch November 6, 2026 23:23
zhangyue19921010 added a commit that referenced this pull request Nov 20, 2026
## Problem

`recent_major_versions` takes the newest stable pylance majors on PyPI
regardless of the code under test. Once 15.0.0 is published,
release/v14.0 would parametrize compat tests over it: its BTREE index on
a stable-row-id table sets `FLAG_ROW_ADDR_INDICES`, which the 14.0
writer refuses exactly as it did with 15.0.0b8.

## Fix

Read the checkout's version from `python/Cargo.toml` and skip stable
releases newer than it. On main this changes nothing, since main is
always the newest version. Stable-only selection (#10578) is preserved;
a checkout at a pre-release such as `15.0.0-beta.25` skips stable
`15.0.0` until the checkout reaches that release. The snapshot test that
copies `compat_decorator.py` out of the tree stubs the source version
like it stubs the release lookup, and now restores the cached release
list after each test.

Forward port of 9256223 from
`origin/release/v14.0` (#10596), adapted to main's #9856 and #10578.

Co-authored-by: Yue Zhang <[email protected]>

Co-authored-by: Yue Zhang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-format On-disk format: protos and format spec docs A-index Vector index, linalg, tokenizer A-python Python bindings enhancement New feature or request 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.

3 participants