Skip to content

[spark][vector] Support appending shards to centroid indexes - #11712

Merged
JingsongLi merged 2 commits into
apache:masterfrom
JingsongLi:codex/centroid-add-shards
Dec 6, 2026
Merged

JingsongLi merged 2 commits into
apache:masterfrom
JingsongLi:codex/centroid-add-shards

Conversation

@JingsongLi

@JingsongLi JingsongLi commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Add sys.add_global_index_shards for Centroid vector indexes on Data Evolution tables. An adjacent append reuses the router and existing index files, builds vector and scalar Bitmap files for the new rows, and commits the complete coverage range atomically. File-local row offsets preserve the mapping from each batch to that range. The unreleased v1 descriptor uses a single 30-byte header with explicit batch geometry for shards and Bitmaps.

Reused files keep their original scan snapshots. Refresh checks use each file's source range and replace the complete Centroid group when it becomes stale. Vector searches also reuse each batch's translated row-ID filter across centroid files and probe rounds.

Tests

  • Spark 3 Centroid SQL and strict Kryo tests cover fresh and stale refreshes, source conflicts during append, Bitmap filtering, and all-null ranges.
  • Java tests cover manifest metadata, refresh planning, commit conflicts, vector queries, and one filter translation and serialization per batch.
  • Python tests cover committing batches with repeated centroid and Bitmap field IDs under the shared manifest range.

Open compatibility work

Cross-engine interoperability needs a matching update to Rust centroid readers, writers, and manifest validation for the 30-byte v1 descriptor. The staged Java abort cleanup and the mixed-schema Bitmap fallback are separate review follow-ups.

@JingsongLi
JingsongLi marked this pull request as ready for review December 6, 2026 05:40

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

Reviewed base master at head 71b51ec0ff3cfaf39fa77f9e7f9ded8736182f51 (+1511/-355, 32 files): docs (centroid-vector.mdx, procedures), common CentroidIndexFile / CentroidShardFilterReader / CentroidVectorGlobalIndexer, core CentroidIndexMeta / DataEvolutionGlobalIndexRefreshPlanner / DataEvolutionConflictDetection / CentroidBitmapFilter / AbstractDataEvolutionVectorRead / GlobalIndexQuery / GlobalIndexVisibilityChecker, Python manifest grouping and source check, Spark add_global_index_shards procedure + CentroidGlobalIndexTopoBuilder / CentroidBitmapFieldAppender, vector NativeCentroidRoutedIndexReader / NativeCentroidVectorGlobalIndexer, tests and updated Rust interop warehouse zips.

Core change notice: this PR carries substantial generic core changes, not just Spark wiring:

  • CentroidIndexMeta: the v1 descriptor header grows from 14 to 30 bytes (rowIdOffset int64 + rowRangeSize int64), so shard/Bitmap files now declare explicit batch geometry inside a shared manifest range. This is a breaking descriptor change; per the PR description v1 is not yet released, and the interop warehouse zips are regenerated accordingly. The matching paimon-rust reader/writer update for the 30-byte header is declared open compatibility work, and staged Java abort cleanup plus mixed-schema Bitmap fallback are declared follow-ups. Cross-engine consumers must land the companion change before reading tables written by this version.
  • DataEvolutionGlobalIndexRefreshPlanner: staleness is now evaluated per batch via the descriptor file range instead of the whole manifest range; any stale batch replaces the whole centroid group, and the router only covers the exclude(populated) span with its own baseline. This keeps null spans and reused files on their original scan snapshots.
  • DataEvolutionConflictDetection.checkCentroidSourceChanges: DELETE routers record removed range ends; an ADD router whose range extends a removed one (previousEnd < newEnd) validates against rowIdCheckFromSnapshot instead of the original router scan snapshot, while pure rebuilds keep the strict original baseline. The Spark test proves an UPDATE inside the newly appended span is still rejected with "Centroid index source rows changed".
  • CentroidBitmapFilter and CentroidBitmapFieldAppender: Bitmap validation and appends are batched by rowIdOffset, each batch checks its own vectorCount/schemaId/field coverage; mixed-schema batches fall back rather than fail.
  • Common interfaces: CentroidShardFilterReader.withShardFilter stays as a default bridge to the new withShardFileFilter, and CentroidVectorGlobalIndexer gains readRoutingModel / forRoutingModel. The shard filter is now keyed by file, not centroid id, which is required once a centroid owns multiple batch files.
  • Python centroid_index_groups.py mirrors the 30-byte header and per-batch validation (sorted non-overlapping batches within range, per-batch Bitmap coverage and schema consistency, router source snapshot as the group floor), keeping Java/Python manifest contracts aligned.

Analysis of the append path:

  • appendShards picks the floor centroid group as template only when rowRangeEnd == source.from - 1 (strict adjacency); non-adjacent unindexed spans become independent groups, verified by the two-range test. IGNORE update policy with non-empty extras is rejected up front, which is the right guard since Bitmap appends cannot replay updated rows.
  • Router reuse: readRoutingModel + forRoutingModel bind metric from router metadata and dimension from the native header, skipping training when a payload exists; retained files keep their descriptors via extendRange (range start unchanged, so file-relative offsets stay valid), and a rewritten router inherits the old sourceMeta so the original null-span baseline survives. The all-null-then-first-vectors test covers training a fresh router over the full extended range.
  • NativeCentroidRoutedIndexReader: shards become per-centroid lists keyed by (centroid, rowIdOffset); SearchFilters caches one BatchFilter per (offset, size) on the coordinator, so localRowIds translation and Bitmap serialization happen once per batch, not per shard. The dedicated test asserts clips == 1 and serializations == 1 across two centroids in one batch. ShardTopK.add restores global ids with Math.addExact(localRowId, offset), and the joint-layout probe requires a single file per centroid, which correctly disables the fused path for multi-batch centroids.
  • localRowIds returns the include set unchanged only when offset == 0 and the last id fits the batch, otherwise it translates via the relative range; empty batches short-circuit before opening shard readers.

Test coverage is strong: Spark SQL tests for adjacent extension without rewriting files (byte-identical retained files), stale staged-commit rejection, repeated no-op appends, schema evolution + Bitmap field append + DELETE visibility, scan-snapshot preservation across range refresh, all-null router training; Java tests for descriptor round-trip/extension, per-batch filter reuse, and Rust interop with the 30-byte header; Python tests for duplicated per-batch field ids under a shared range.

No findings.

CI: 47 checks pass (all Python/native/interop/licensing), 8 Java suites still pending. Author ran Spark 3 centroid SQL tests with strict Kryo, Java manifest/planner/conflict/query tests, and Python commit tests locally. Approving without waiting for the remaining CI, as requested.

LGTM.

@JingsongLi
JingsongLi merged commit 1fa696b into apache:master Dec 6, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants