Skip to content

refactor(index): use arrow stats for scalar index stats - #6808

Merged
westonpace merged 1 commit into
mainfrom
replace-scalar-index-stats-arrow-stats
May 28, 2026
Merged

westonpace merged 1 commit into
mainfrom
replace-scalar-index-stats-arrow-stats

Conversation

@HaochengLIU

@HaochengLIU HaochengLIU commented May 16, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Replace zonemap DataFusion min/max accumulators with lance_arrow_stats::StatisticsAccumulator.
  • Use arrow_stats to track bloom filter zone null counts.
  • Keep scalar-index NaN handling local to Lance instead of importing DataFusion math UDFs.
  • Add lance-arrow-stats to the lance-index dependency graph and update the Python lockfile.

Testing

  • All tests pass.

@github-actions

Copy link
Copy Markdown
Contributor

ACTION NEEDED
Lance follows the Conventional Commits specification for release automation.

The PR title and description are used as the merge commit message. Please update your PR title and description to match the specification.

For details on the error please inspect the "PR Title Check" action.

@HaochengLIU
HaochengLIU force-pushed the replace-scalar-index-stats-arrow-stats branch from d6405d3 to 9aa30a8 Compare May 16, 2026 15:45
@HaochengLIU HaochengLIU changed the title Use arrow stats for scalar index zone stats refactor(index): use arrow stats for scalar index stats May 16, 2026
@codecov

codecov Bot commented May 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance-index/src/scalar/zonemap.rs 74.39% 15 Missing and 6 partials ⚠️
rust/lance-index/src/scalar/bloomfilter.rs 92.30% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@HaochengLIU
HaochengLIU force-pushed the replace-scalar-index-stats-arrow-stats branch from 9aa30a8 to 921f623 Compare May 16, 2026 18:14
@github-actions github-actions Bot added the A-python Python bindings label May 16, 2026
@HaochengLIU
HaochengLIU force-pushed the replace-scalar-index-stats-arrow-stats branch 3 times, most recently from 6e67ae1 to 156695b Compare May 17, 2026 00:27
@HaochengLIU
HaochengLIU marked this pull request as ready for review May 17, 2026 02:30

@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 to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

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

@HaochengLIU

Copy link
Copy Markdown
Member Author

@claude review once

@HaochengLIU
HaochengLIU force-pushed the replace-scalar-index-stats-arrow-stats branch from 156695b to 2f8a18d Compare May 20, 2026 00:56
@HaochengLIU

Copy link
Copy Markdown
Member Author

@westonpace @jackye1995 can any of you review this PR? ty

@westonpace westonpace left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is great, some small suggestions but thanks for cleaning this up!

Comment on lines +135 to +142
fn scalar_is_nan(value: &ScalarValue) -> bool {
match value {
ScalarValue::Float16(Some(value)) => value.is_nan(),
ScalarValue::Float32(Some(value)) => value.is_nan(),
ScalarValue::Float64(Some(value)) => value.is_nan(),
_ => false,
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's add is_nan to ArrowScalar in the arrow-scalar crate?

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.

added

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So now we can get rid of this function right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, I see, we are still using datafusion scalars (and not just in zonemap but in sargablequery too 😦). I'll handle that cleanup.

Comment thread rust/lance-index/src/scalar/zonemap.rs Outdated
}
}

fn zone_has_extrema(zone: &ZoneMapStatistics) -> bool {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
fn zone_has_extrema(zone: &ZoneMapStatistics) -> bool {
/// Returns true if both min and max are non-null / non-nan
fn zone_has_extrema(zone: &ZoneMapStatistics) -> bool {

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.

break the function into a few for better readability

Comment thread rust/lance-index/src/scalar/zonemap.rs Outdated
Comment on lines +184 to +186
if !Self::zone_has_extrema(zone) {
return Ok(false);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this safe? If we are using total ordering for floats then is it possible the min is -NaN and the max is NaN and the value we are looking for is somewhere in between?

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.

reworked the logic.
- Replaced the vague zone_has_extrema helper with:
- zone_has_finite_min
- zone_has_finite_extrema
- finite_value_may_be_in_zone
- The important behavior is unchanged: if a zone has finite values plus NaNs, we store max = NaN to match the old DataFusion shape, but we do not use NaN as a real finite upper bound.
- For finite lookups, a NaN max means “unknown finite max,” so zonemap keeps the zone as a false positive instead of incorrectly pruning it

@HaochengLIU
HaochengLIU force-pushed the replace-scalar-index-stats-arrow-stats branch from 2f8a18d to 67da885 Compare May 26, 2026 23:02
@HaochengLIU
HaochengLIU requested a review from westonpace May 26, 2026 23:13

@westonpace westonpace left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have one more thing I want to try but let's move forward

@westonpace
westonpace merged commit 26edc4a into main May 28, 2026
28 checks passed
@westonpace
westonpace deleted the replace-scalar-index-stats-arrow-stats branch May 28, 2026 12:26
Xuanwo added a commit that referenced this pull request Nov 23, 2026
…arrow (#11294)

cc @westonpace — opening this PR to consolidate `lance-arrow-scalar` and
`lance-arrow-stats` into `lance-arrow` ahead of the `v15.0.0` release.
Happy to hear your thoughts if you still want to keep them as standalone
Arrow-versioned crates!

## Context

While preparing the `v15.0.0` stable release, we hit a hard Rust publish
blocker:

1. **Blocked `v15.0.0` crates.io publish**: `#10397` bumped
`lance-arrow-scalar` and `lance-arrow-stats` to `59.0.0` (pinned via
`=59.0.0` in the root `Cargo.toml`), while crates.io still only has
`58.0.0`. `.github/workflows/cargo-publish.yml` excludes both crates
(`--exclude lance-arrow-stats --exclude lance-arrow-scalar`), and there
is no other publish workflow, so `cargo publish --workspace` fails
immediately when resolving `lance-index`.
2. **Silent source drift on crates.io**: Because these two crates track
Arrow's major version instead of `workspace.package.version` and were
excluded after `#6972`, changes in `#6808` (`ArrowScalar::is_nan`) and
`#7966` (`Decimal128/Decimal256` min/max stats) landed without bumping
`58.0.0`. Rust users installing `lance 8.x–14.0.3` from crates.io
received the stale May `58.0.0` tarball instead of the workspace source,
and `#10102` added further Lance-specific ZoneMap seed NaN tracking on
top.
3. **Zero external usage & single-owner publishing**: On crates.io, both
crates have only internal Lance reverse dependencies
(`lance-arrow-stats`, `lance-index`, `lance`) and a single crate owner
(missing `github:lancedb:release`).
4. **Original goal still holds in `lance-arrow`**: The original
motivation in `#5955` / `#5967` was to avoid pulling DataFusion into
lower-level crates. `lance-arrow` has zero DataFusion dependencies, is
already depended on by `lance-encoding`, `lance-file`, `lance-core`, and
`lance-index`, and follows `workspace.package.version` cleanly.

Since `v15.0.0` is already a breaking major (Arrow 59 / DataFusion 55)
and crates.io SemVer prevents downgrading `59.0.0` back to `15.0.0`
under the old crate names, merging them into `lance-arrow` removes the
dual-track versioning and publish exclusions cleanly.

## Changes

- Move `ArrowScalar` (and its `From` conversions) into
`lance_arrow::scalar::ArrowScalar` (`rust/lance-arrow/src/scalar/`).
- Drop the unused custom binary scalar codec
(`rust/arrow-scalar/src/serde.rs`, 558 lines with zero callers outside
its own unit tests).
- Move `StatisticsAccumulator`, `Statistics`, `NanCounts`, `count_nans`,
and `count_nans_signed` into `lance_arrow::stats`
(`rust/lance-arrow/src/stats.rs` and
`rust/lance-arrow/src/stats/nan.rs`), along with its proptest regression
seeds (`rust/lance-arrow/proptest-regressions/stats.txt`).
- Add `arrow-cast` and `arrow-row` to `rust/lance-arrow/Cargo.toml`
(both are already workspace Arrow dependencies; `lance-arrow` remains
free of DataFusion).
- Update internal callers (`lance-index` zonemap/bloomfilter and
`rust/lance/tests/arrow_ordering.rs`) and remove `rust/arrow-scalar` and
`rust/arrow-stats` from the workspace and all three lockfiles
(`Cargo.lock`, `python/Cargo.lock`, `java/lance-jni/Cargo.lock`).
- Drop `--exclude lance-arrow-stats --exclude lance-arrow-scalar` from
`.github/workflows/cargo-publish.yml`, and update the
`arrow-ordering-compat` path trigger in `.github/workflows/rust.yml` and
`rust/AGENTS.md`.

## Notes on `arrow-ordering-compat`

No ordering expectations in `rust/lance/tests/arrow_ordering.rs`
changed—only the two `use` imports were updated from
`lance_arrow_scalar` / `lance_arrow_stats` to `lance_arrow::scalar` /
`lance_arrow::stats`. Because the base branch's copy of
`arrow_ordering.rs` still references the removed crates, the base-branch
compile check in `arrow-ordering-compat` will need the
`arrow-ordering-reviewed` label once reviewed.

## Verification

- `cargo fmt --all -- --check`
- `cargo test --profile ci --locked -p lance-arrow` (366 passed,
including 34 `scalar::arrow_scalar`, 4 `scalar::convert`, 64 `stats::`,
and 9 doctests)
- `cargo test --profile ci --locked -p lance-index --lib
'scalar::zonemap::tests'` (85 passed) and `'scalar::bloomfilter::tests'`
(36 passed)
- `cargo test --profile ci --locked -p lance --test arrow_ordering` (46
passed)
- `RUSTDOCFLAGS="-D warnings" cargo doc --profile ci --locked --no-deps
-p lance-arrow`
- `cargo clippy --profile ci --locked --all --tests --benches -- -D
warnings`
- `cargo clippy --profile ci --locked -p lance --test arrow_ordering --
-D warnings`
- `cargo package --workspace --no-verify --all-features` and `cargo
publish --workspace --all-features --dry-run --no-verify` (all 28
workspace crates resolve and pass dry-run)
- `cargo metadata --frozen` verified across `Cargo.toml`,
`python/Cargo.toml`, and `java/lance-jni/Cargo.toml`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-python Python bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants