Skip to content

feat: create an arrow-scalar crate utilizing arrow-row and arrow-data - #5955

Merged
westonpace merged 4 commits into
lance-format:mainfrom
westonpace:feat/arrow-scalar-arr
Feb 18, 2026
Merged

westonpace merged 4 commits into
lance-format:mainfrom
westonpace:feat/arrow-scalar-arr

Conversation

@westonpace

Copy link
Copy Markdown
Member

This provides an ArrowScalar which supports:

  • Implementations of Ord, Hash, and Eq
  • Stable serialization to/from binary

The Ord/Eq implementations come from arrow_row which should provide the same comparison logic as arrow-rs compute functions (and thus Datafusion)

The binary serialization uses the C data interface for optional serialization of the data type and then dumps the array data as-is. This should be a stable format.

My primary goal with this PR was to minimize the amount of code required (compared to something like datafusion's ScalarValue to keep maintenance simple. There may be more performant options but since I don't expect scalars to be used in hot spots I think this will be ok. Also, the public API surface of ArrowScalar is pretty small so if we need to replace the internal implementation later for performance we can do so.

@github-actions github-actions Bot added the enhancement New feature or request label Feb 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Review: arrow-scalar crate

This PR introduces a new ArrowScalar type with Ord, Hash, and Eq support via arrow_row. Overall, the design is clean and the code is well-tested.

P0/P1 Issues

1. (P1) Missing BinaryView/Utf8View serialization test coverage
serde.rs has format string mappings for BinaryView/Utf8View (lines 643-644, 698-699), but there's no roundtrip test for these types. Views have variadic buffers (inline vs. out-of-line data), and the current buffer serialization may not correctly handle this. Consider adding a test to verify these types serialize/deserialize correctly, or explicitly document that views are unsupported for encoding.

2. (P1) Potential panic on invalid buffer counts during decode
In decode_with_options, the code builds ArrayData with whatever buffers are in the encoded bytes (rust/arrow-scalar/src/serde.rs:895-900). If the buffer count doesn't match what the DataType expects, builder.build() will fail. This is handled as an error, but the error message from Arrow may be unclear. Consider validating expected buffer counts before building to provide a clearer error message.

3. (P0) Boolean arrays have no value buffer when using packed bits
For DataType::Boolean, the value data is stored in a bitmap buffer which may not be captured correctly by iterating data.buffers(). The current approach copies data.buffers() which for boolean arrays may be empty or not include the validity buffer correctly. This could cause boolean scalars to fail encode/decode roundtrip. Please verify with a test:

let b = ArrowScalar::from(true);
let encoded = b.encode().unwrap();
let decoded = ArrowScalar::decode(&encoded).unwrap();
assert_eq!(b, decoded);

Minor Notes (not blocking)

  • The crate version is hardcoded to 57.0.0 which matches current arrow-rs, but consider whether this should track lance's versioning scheme instead.
  • The README.md referenced in Cargo.toml doesn't exist yet.

@codecov

codecov Bot commented Feb 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.28373% with 113 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/arrow-scalar/src/serde.rs 67.36% 81 Missing and 28 partials ⚠️
rust/arrow-scalar/src/lib.rs 98.81% 0 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

Comment on lines +14 to +15
[dependencies]
arrow-array = { workspace = true }

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.

If you want to be defensive, might want to leave a brief comment that you want to keep the dependency list here small.

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

Looks reasonable and small.

@westonpace
westonpace merged commit 884d18e into lance-format:main Feb 18, 2026
27 of 28 checks passed
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

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants