Repository navigation
feat: compute min/max zone statistics for fixed-size binary columns - #11387
Conversation
Co-Authored-By: Claude <[email protected]>
The statistics module moved from the arrow-stats crate to lance-arrow/src/stats.rs; the FixedSizeBinary arm and its tests follow it. Co-Authored-By: Claude <[email protected]>
wjones127
left a comment
There was a problem hiding this comment.
Thanks, this is a nice small fix: zone maps on UUID/hash columns now get real bounds, and their seeds stop being thrown away. The order matches Binary and make_comparator.
One thing blocks: FSB extrema are now persisted, so their byte order is part of the on-disk contract and should be pinned in arrow_ordering.rs (inline).
Non-blocking:
- I'd prefer to drop the dataset-level seed test in favor of unit coverage (inline).
- thought: FSB zone maps written before this change have null bounds on zones that hold values, like legacy Decimal zones. The handling is type-agnostic, so old indices should fall back conservatively, but the comment here only names Decimal. Maybe mention FixedSizeBinary too? Fine as a follow-up.
| LargeBinary => find_extrema_bytes!(array, as_binary::<i64>), | ||
| // Unsigned lexicographic byte order, matching the FixedSizeBinary arm | ||
| // of `arrow_ord::ord::make_comparator`. | ||
| FixedSizeBinary(_) => find_extrema_bytes!(array, as_fixed_size_binary), |
There was a problem hiding this comment.
issue(blocking): Could we add a FixedSizeBinary fixture to rust/lance/tests/arrow_ordering.rs?
Zone maps now persist extrema for this type, and pruning depends on three comparators agreeing: the extrema scan here, ArrowScalar (merge), and ScalarValue::partial_cmp (zone eval). That file is where we pin those orders so that an Arrow or DataFusion upgrade that changes one fails loudly instead of silently mis-pruning old indices. fixtures() runs every path for each type listed, so this is just a new fixture modeled on binary():
lance/rust/lance/tests/arrow_ordering.rs
Lines 563 to 585 in 4b3227c
To pin unsigned order, include values that straddle 0x7F/0x80 and 0xFF in the leading byte (e.g. [00 00], [00 01], [7F FF], [80 00], a duplicate, [FF 00], [FF FF]). The zone map unit test only uses bytes below 0x80.
Done when fixtures() includes a FixedSizeBinary fixture with high-bit leading bytes.
There was a problem hiding this comment.
Done in 6551a98. arrow_ordering.rs has a fixed_size_binary() fixture (width 2) registered in fixtures(): [00 00], [00 01], [7F FF], [80 00], a duplicate [80 00], [FF 00], [FF FF], plus a null, so the leading byte straddles 0x7F/0x80 and reaches 0xFF.
| /// rebuilt zone map reuses them instead of rejecting them as unbounded and | ||
| /// scanning, and the index answers filters like an unindexed scan. | ||
| #[tokio::test] | ||
| async fn test_fixed_size_binary_seed_is_reused() { |
There was a problem hiding this comment.
suggestion: Can we drop the dataset-level test here? I'd like to avoid adding tests that build an index on a dataset when we can, since they're several orders of magnitude slower than unit tests.
Seeds and training both compute bounds through ZoneMapProcessor -> StatisticsAccumulator, and validate_seed only rejected FSB seeds because their bounds were null. So the stats.rs tests plus test_fixed_size_binary_zonemap_prunes already cover the fix (and the arrow_ordering.rs fixture above pins the order). If we want explicit seed coverage, a ZoneMapSeedWriter + validate_seed unit test next to test_seed_v1_round_trip_and_validation would pin it much more cheaply.
There was a problem hiding this comment.
Done in 6551a98. The dataset-level test is removed, and test_seed_fixed_size_binary_bounds_are_reusable sits next to test_seed_v1_round_trip_and_validation: it checks that validate_seed accepts a FixedSizeBinary seed and that each record's bounds are non-null and in unsigned byte order, using values with high-bit leading bytes.
Add a FixedSizeBinary fixture to the Arrow ordering tests with leading bytes that straddle 0x7F/0x80 and reach 0xFF, since zone maps now persist extrema for this type. Replace the dataset-level seed test with a seed writer and validation unit test, and name FixedSizeBinary in the comment on legacy zones that have values but no extrema. Co-Authored-By: Claude <[email protected]>
…inary-zone-stats # Conflicts: # rust/lance-index/src/scalar/zonemap.rs
|
@wjones127 thanks for the review. Both inline points are addressed in 6551a98. I also took the non-blocking thought: the comment on legacy zones with values but no extrema in |
wjones127
left a comment
There was a problem hiding this comment.
Nice! Thanks for responding to my feedback.
Summary
Zone statistics had no min/max for
FixedSizeBinarycolumns (UUIDs, hashes):find_min_max_indicesinarrow-statsfell through to the unsupported arm, so every zone stored null bounds.Consequences before this change:
IS NULL; equality, range andINfilters kept every zone that held a non-null value.FixedSizeBinary(n)withn > 8. The write paid for a seed that could not be used.Change
Add a
FixedSizeBinaryarm that computes min/max with unsigned lexicographic byte order, the same order used forBinaryand the order of theFixedSizeBinaryarm ofarrow_ord::ord::make_comparator. Running min/max accumulation and merging already compare throughArrowScalarand needed no change.No other type is added. View types are stored as their base types, and dictionary columns would need a key-aware pass.
Tests
arrow-stats: bounds with nulls, all-null input, multi-batch update and merge (width 16).FixedSizeBinary(16)column and pruning for equality, range,INandIS NULL.FixedSizeBinary(16)column is reused by the index build and filters answer like an unindexed scan.🤖 Generated with Claude Code