Repository navigation
perf(encoding): accelerate ByteStreamSplit with SIMD byte transpose - #10905
Merged
Merged
Conversation
There was a problem hiding this comment.
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.
BubbleCal
approved these changes
Nov 10, 2026
This was referenced Nov 11, 2026
BubbleCal
pushed a commit
that referenced
this pull request
Nov 11, 2026
…element (#10947) ## Summary Filters can now use the lambda form for per-element predicates on `list<struct>` columns: ```sql array_any_match(detections, d -> d.label = 'car' AND d.confidence > 0.9) ``` While parsing the filter, Lance rewrites it to the `any_element` call from #10901: ```sql any_element(detections, 'label = ''car'' AND confidence > 0.9') ``` The two forms behave the same. The lambda never reaches DataFusion's lambda planning, Substrait or execution, so the DataFusion gaps listed in #10873 don't apply. This is track 1 of #10873. General lambda support, track 2, still waits on DataFusion. ## Design - **Dialect:** `LanceDialect` enables `supports_lambda_functions`. Without it, `->` parses as the JSON arrow operator, which Lance already rejects, so no accepted filter changes meaning. `->>` is unaffected. - **Rewrite:** `Planner::parse_filter` rewrites the parsed SQL before planning it. `array_any_match` and its alias `any_match` with a one-parameter lambda become `any_element(list, '<body>')`: - `d.label`, `d.details.kind` and `d['my field']` become `label`, `details.kind` and `` `my field` ``. - The body is printed back as SQL and becomes the predicate literal, so Lance's own literal handling applies inside it. - The list argument must be a `list<struct>` column. Its type is checked against the schema. - **Clear errors** for anything `any_element` can't express: - a column outside the element, or a bare `label` without the parameter; - the parameter itself (`d IS NOT NULL`); - a numeric subscript (`d[1]`); - two parameters; - a nested lambda; - an argument that isn't a `list<struct>`; - a lambda in any other function, such as `array_filter`, or outside a function. ## Tests - **Dialect:** a lambda argument with a bare and a parenthesized parameter, and that `->>` is not a lambda. - **Rewrite:** 7 forms, including the alias, nested fields, subscripts, a double-quoted string, and inside `NOT`, `AND` and another function call. 9 error cases, each checked for a message that says what to change. - **Dataset**, on #10901's fixture: - three lambda cases: the basic form, the alias with a subscript, and `NOT` combined with an indexed column. Each is checked against a reference evaluation with and without the scalar index, and through `count_rows`. - two rejection cases, through the scanner and `count_rows`. ## Docs A paragraph on the lambda form in the "Filtering on elements of a list of structs" section of the read and write guide. Part of #10873. Lint: `cargo fmt --all`, and `cargo clippy --no-deps -p lance-datafusion -p lance --features lance-datafusion/substrait --tests -- -D warnings`. With dependencies included, clippy on arm64 currently fails in `lance-encoding` (`unreachable_code` in `byte_stream_split.rs`, from #10905). That code isn't touched here, and x86 CI doesn't hit it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
BubbleCal
pushed a commit
that referenced
this pull request
Nov 12, 2026
… elements (#10950) ## Summary Adds `listelement`, an experimental built-in scalar index over fields inside the elements of a `list<struct>` column. It answers `any_element` filters (#10901) from the index, with every condition on the same element: ```python dataset.create_scalar_index( "detections", IndexConfig(index_type="listelement", parameters={"keys": ["label", "confidence"]}), ) dataset.to_table(filter="any_element(detections, 'label = ''car'' AND confidence > 0.9')") ``` This is the second part of #10900. The format is specified in #10949, and the design discussion is #10948. **Depends on #10949.** This PR carries the identical `protos/index.proto` change and generated source so that it compiles. Those changes drop out when this branch is rebased after #10949 merges. ## Design - **Training:** one entry per element. - The key is the element's `keys` fields as a tuple, encoded with Arrow's row format (ascending, nulls first), so the bytes sort like the tuples. - The posting is the row address. - Entries are sorted with spilling, and an ordinary BTREE is trained over the `Binary` keys. The index wraps the BTREE the way the JSON index wraps its target. - **Search:** `visit_scalar_function` claims `any_element(<indexed column>, '<literal>')`. The predicate is planned exactly as `any_element` plans it, then with the tuple planner (`plan_tuple_predicate`) over the keys. - **Seeks:** an `=`, `IN` or `IS NULL` prefix, then one range on the next key, becomes byte-range seeks in the BTREE. - **Superset and recheck:** conditions the keys can't express, such as a field that isn't a key, make the answer a superset. The scan then rechecks it with `any_element`. - **No first key, no index:** without a condition on the first key, the index declines. - **NULLs:** NULL lists, and elements on which the predicate is NULL, are tracked, so `NOT` is exact. - **Maintenance:** update encodes the new fragments the same way, then defers to the BTREE. Remap defers to the BTREE. - **Row addresses:** in `lance-table`, the index joins the row-address and eager-remap lists. On stable-row-ID tables, the #10352 writer fence applies and compaction remaps the index. - **`lance-datafusion` API:** it exports `ANY_ELEMENT`, `any_element_predicate` and `plan_element_predicate`, so the index plans the same expression the scan evaluates. `lance-index` now depends on `lance-datafusion` as a normal dependency; there's no cycle. ## Fix included On a stable-row-ID table, `optimize_indices` dropped old entries of a row-address index outside fragment 0. The generic update arm in `merge_scalar_indices` only treated the JSON index as storing row addresses, so it filtered row addresses against row IDs. That arm now also covers this index. JSON behavior is unchanged. ## Tests - **Index unit tests** (13): - same-element trap, every range operator, `IN`, label-only prefix, recheck; - NULL rows for `NOT`; - shapes the index declines; - details round trip, and invalid parameters (no keys, unknown key, repeated key, nested key type, unknown parameter, non-struct list); - segment key mismatch, an all-null column, and the spec's encoding bytes. - **`lance-table`:** row-address and eager-remap classification. - **Dataset tests:** #10901's fixture is extended rather than duplicated. - Every filter case, plus the edge-row and invalid-predicate tests, runs with and without the index, checking the plan and whether it rechecks. - New: declining when the first key isn't constrained; `fast_search` plus `optimize_indices`; delete plus compaction remap, with and without stable row IDs. ## Docs The read and write guide covers creating the index and which filters it answers, and the scalar indexing guide has a row for it. Both mark it experimental. ## Not in this PR - **Training memory:** there's no explicit budget. Like the JSON index, training uses the default spill pool. At 100M elements the prototype needed `LANCE_MEM_POOL_SIZE=8GiB`. - **Merging segments** for distributed builds. - **Fragment reuse index:** batch row-ID remapping isn't supported. Like JSON, the index is reported incompatible on stable-row-ID tables that use a fragment reuse index. Closes #10900. This conflicts with #10947 in the dataset scanner tests and the guide. Whichever merges second will rebase. Lint: `cargo fmt --all`, and `cargo clippy --no-deps -p lance-datafusion -p lance-index -p lance-table -p lance --tests --benches --features lance-datafusion/substrait -- -D warnings`. With dependencies included, clippy on arm64 currently fails in `lance-encoding` (`unreachable_code` from #10905), which this PR doesn't touch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ByteStreamSplitEncoderandByteStreamSplitDecompressorpreviously zero-initialized output buffers withvec![0u8; total_bytes]before overwriting every byte and transposed byte streams with a runtime-strided scalar loop (0..self.bytes_per_value) that could not vectorize into SIMD byte-shuffle instructions.Write directly into uninitialized
Vec<u8>capacity after validating buffer lengths, specialize stream widths4(f32) and8(f64), and addx86_64AVX2andaarch64NEONbyte-transpose kernels with scalar tail handling. On-disk encoding and metadata are unchanged.Benchmark
End-to-end Lance v2.2 in-memory
FileWriterandFileReaderfull-scan throughput over 4 MiBRecordBatchcolumns (1,048,576Float32values /524,288Float64values), comparingmain(5e75eb100b) againstd72ea0c39conAMD EPYC 4585PX(release-with-debug, single pinned core, median across 7 alternating paired rounds):mainFloat32write (compression=lz4, defaultbss=auto)Float32full scan (compression=lz4, defaultbss=auto)Float64write (compression=lz4, defaultbss=auto)Float64full scan (compression=lz4, defaultbss=auto)Float32full scan (high-entropybss=on)Float64full scan (high-entropybss=on)