Commit c9dcf64
committed
feat(sql): support USING zonemap in CREATE INDEX
Adds `ALTER TABLE ... CREATE INDEX ... USING zonemap (col)` end-to-end with
a properly distributed multi-segment build.
Two production-side changes:
1. IndexUtils now recognises "zonemap" as a method name in both directions
(buildIndexType → IndexType.ZONEMAP, buildScalarIndexParamType → "zonemap")
with case-insensitive lookup.
2. AddIndexExec routes ZONEMAP through a new runZonemapDistributed path.
Unlike the FragmentBasedIndexJob shared-UUID pattern (which BTree uses
correctly because per-partition writes use distinct file names —
part_<id>_page_data.lance, part_<id>_page_lookup.lance — and a merge step
consolidates them), ZoneMap writes a fixed `zonemap.lance` filename and has
no merge step. Sharing one UUID across N executor tasks would race on the
same object-store path; only one fragment's data would survive.
Each Spark task now calls dataset.createIndex with withFragmentIds=[id]
and NO withIndexUUID. The lance-core JNI takes the execute_uncommitted
path (skip_commit = fragment_ids.is_some()) and generates a fresh
per-task UUID, so each task writes to its own indices_dir/<uuid>/zonemap.lance
directory. The driver collects all N per-task ZonemapFragmentResult values
(uuid, fragmentId, indexDetails, indexVersion, createdAt) and commits them
as a single AddIndexOperation transaction with N IndexMetadata entries
sharing the index name. lance-core's existing read-side infrastructure —
describe_indices chunking by name, getZonemapStats iterating
load_indices_by_name and reading each segment's zonemap.lance — handles
the multi-segment shape transparently.
mergeIndexMetadata is intentionally skipped for ZONEMAP: there is no
per-fragment file consolidation needed, and lance-core's merge_index_metadata
has no ZoneMap arm anyway (would throw "Unsupported index type").
Supporting refactors:
- Extract resolveFieldIdsOrThrow(dataset, columns) — shared by the parallel
path's post-build commit and the new distributed ZoneMap path. Single source
of truth for the "Cannot find index column in Lance schema" error.
- Extract extractNamespaceInfo(lanceDataset, readOptions) — shared between
createIndexJob and runZonemapDistributed.
- ZonemapFragmentTask wraps execute() in try/catch that re-throws with
fragment-id context, preserving the specific exception subclass
(IllegalArgumentException, IllegalStateException, RuntimeException) so
callers matching on type still match.
- Driver-side decoding of per-task results wraps decode failures with
task-index context so deploy-skew / serialization issues are diagnosable.
- runZonemapBuild validates that createdIndex.indexDetails() is non-empty,
mirroring the parallel path's extractIndexBuildResult guard.
Tests:
IndexUtilsTest (6 cases) — symbol-mapping unit tests for buildIndexType /
buildScalarIndexParamType: forward and reverse mappings, case-insensitive
lookup, unknown-method rejection with message substring assertions.
BaseAddIndexTest additions (5 zonemap cases):
- testCreateZonemapIndex — end-to-end USING zonemap + strict per-fragment
coverage assertion (every indexed fragment must contribute ≥1 zone).
- testCreateZonemapOnNonExistentColumn — fail-fast IllegalArgumentException
with "Cannot find index column" message substring.
- testCreateZonemapOnStringColumn — strict assertion that every zone's
min/max is a non-null String (catches string-codec regressions).
- testCreateZonemapWithZoneSize — smoke test for `with (zone_size=N)`
parameter forwarding through IndexUtils.toJson.
- testZonemapDistributedCommitShape — locks the multi-segment commit
invariants: exactly one IndexMetadata per fragment, every segment has a
distinct UUID, every segment's fragment-bitmap is a singleton, the union
of segment fragment-bitmaps equals the indexed fragment set, all segments
share one field-id list. A regression to shared-UUID single-segment
commits — the original race — would fail every assertion in this test.
Verified end-to-end against lance-core 6.0.0-rc.2 (current upstream/main).
Closes #512. Closes #514.1 parent 4332b60 commit c9dcf64
3 files changed
Lines changed: 496 additions & 24 deletions
File tree
- lance-spark-base_2.12/src
- main/scala/org/apache/spark/sql/execution/datasources/v2
- test/java/org/lance/spark
- index
- update
Lines changed: 243 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
86 | 85 | | |
87 | | - | |
88 | 86 | | |
89 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
90 | 93 | | |
91 | 94 | | |
92 | 95 | | |
93 | 96 | | |
94 | | - | |
| 97 | + | |
95 | 98 | | |
96 | 99 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 100 | + | |
105 | 101 | | |
106 | 102 | | |
107 | 103 | | |
| |||
148 | 144 | | |
149 | 145 | | |
150 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
151 | 284 | | |
152 | 285 | | |
153 | 286 | | |
154 | 287 | | |
155 | 288 | | |
156 | 289 | | |
157 | 290 | | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
| 291 | + | |
| 292 | + | |
171 | 293 | | |
172 | 294 | | |
173 | 295 | | |
| |||
353 | 475 | | |
354 | 476 | | |
355 | 477 | | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
356 | 573 | | |
357 | 574 | | |
358 | 575 | | |
| |||
562 | 779 | | |
563 | 780 | | |
564 | 781 | | |
| 782 | + | |
565 | 783 | | |
566 | 784 | | |
567 | 785 | | |
| |||
570 | 788 | | |
571 | 789 | | |
572 | 790 | | |
| 791 | + | |
573 | 792 | | |
574 | 793 | | |
575 | 794 | | |
| |||
Lines changed: 72 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
0 commit comments