Repository navigation
test: pin the Arrow ordering contract with a CI-gated lance-compat crate - #9810
Conversation
d9e4f9d to
0a49db5
Compare
0a49db5 to
4edfe46
Compare
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.
4edfe46 to
6c809b9
Compare
|
Correction: the red Python The Rebased onto current main (9b03cdc, no change to the commit's content) so the next run picks up the fix. The checks this PR owns were already green: |
Lance follows Arrow Rust's total order (IEEE totalOrder for floats, byte-wise for strings and binary, nulls first ascending for index training) rather than defining its own, and DataFusion's sort, TopK, merge and ScalarValue paths on top of it. The versions are declared once in the workspace Cargo.toml and the contract spans queries, indices and statistics, so the fixtures live in a new test-only `lance-compat` crate at the leaf of the workspace graph. `tests/arrow_ordering.rs` holds thirteen typed fixtures (f64/f32/f16, Utf8/LargeUtf8/Binary, Int64/UInt64, Date32, Timestamp ns, Decimal128/256, Boolean) with hand-written expected orders, written from the IEEE and byte-wise definitions rather than generated by Arrow. Special floats are built from bit patterns and compared by bits; ties are compared as groups so an unstable sort is not over-asserted. Each fixture runs through sort_to_indices, lexsort_to_indices, make_comparator, ArrowNativeTypeOp::compare, RowConverter under all four SortOptions, the arrow_row encoding behind ArrowScalar, StatisticsAccumulator extrema (with signed-zero-only inputs, since NaN and signed zero are where sorting and statistics differ), ScalarValue and OrderableScalarValue, SortExec with and without a fetch, and SortPreservingMergeExec. Every disagreement in a test is collected and reported together with the type, inputs, expected and actual order. The test target is `test = false` so the default run stays unchanged; the clippy job lints it in its own invocation because `--all-targets` skips it. Two jobs in the Rust workflow run it when it can tell us something. `arrow-ordering-detect` runs on a small runner for every PR: ci/arrow_upgrade.py compares the base and head Cargo.lock and reports any arrow*, datafusion* or half crate whose (version, source) changed, with release-notes links and the review checklist in the job summary; a change to rust/lance-compat, the jobs, the detector, or the arrow-scalar / arrow-stats crates also counts, so the check itself never merges untested. The base is the merge commit's first parent, so a re-run after the base branch moved compares against what was actually merged. `arrow-ordering-compat` then runs the base branch's fixture file against the new dependencies first, so an upgrade cannot pass by refreshing expectations in the same PR; a reviewed change is admitted by the `arrow-ordering-reviewed` label, read live with `gh` so a re-run after labelling sees it. A base fixture that no longer compiles is reported as a port, not as an ordering finding, and the PR's own copy runs after. The job builds without `-D warnings` because default features leave feature-gated code dead and a bump may deprecate an API the base fixtures use. The detector has unit tests in ci/test_arrow_upgrade.py, run by the CI-scripts workflow. rust/AGENTS.md records the upgrade review procedure: a failure is a finding to classify and trace, not an expectation to refresh.
6c809b9 to
9b03cdc
Compare
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The approach fits Lance’s inherited ordering contract. Checking the base expectations against upgraded dependencies before the PR’s fixtures provides the intended guard against silently refreshing that contract. No blocking issues found.
westonpace
left a comment
There was a problem hiding this comment.
I have no real concern since the extra tests only run in rare scenarios and depend on stable 3rd party APIs so are unlikely to need much maintenance (I hope).
I do wonder slightly if this might be overkill but I'm happy proceeding with it as it is.
Do we actually document in our spec that we rely on Arrow ordering? If we don't then we probably should although that could be a separate PR (as it would need a vote).
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright The Lance Authors | ||
|
|
||
| //! Compatibility fixtures for the upstream contracts Lance inherits. |
There was a problem hiding this comment.
This is an interesting structure for solving this problem. Do you think we really need a new crate? Couldn't these just be integration tests in lance which is already sort of our "primary leaf crate"?
| //! Lance defines no comparison rules of its own. Scalar indices, column | ||
| //! statistics and `ORDER BY` all inherit the total order implemented by Arrow | ||
| //! Rust, and by DataFusion on top of it. These tests pin that order with | ||
| //! hand-written expectations so that an upgrade which changes it fails here, | ||
| //! naming the type, the inputs and both orderings, instead of silently | ||
| //! reordering btree pages, zone map extrema or query results. |
There was a problem hiding this comment.
Is there a concern that Arrow might change its ordering rules? That seems pretty unlikely.
There was a problem hiding this comment.
It seems unlikely to change frequently, but there is a precedent: Arrow Rust #2614 changed floating-point comparison semantics in 2022.
Previously, behavior depended on the compile-time nan_ordering option:
| Case | Option off | Option on |
|---|---|---|
| NaN vs. ordinary numbers | Neither less nor greater | All NaNs greater than ordinary numbers |
| Two NaNs | Not equal | Treated as equal |
-0.0 vs. +0.0 |
Equal | Equal |
The affected comparison kernels switched to total_cmp, following IEEE 754 totalOrder, and removed that option:
negative NaNs < -∞ < negative numbers < -0.0
< +0.0 < positive numbers < +∞ < positive NaNs
Ordinary comparisons such as 1.0 < 2.0 did not change. The tests are a safeguard against changes or regressions in these edge cases, rather than an expectation that Arrow frequently changes its ordering rules.
The fixtures need no crate of their own: `lance` is already the leaf of the workspace and has every dependency they use. They become a `test = false` integration test of `lance`, so the default test run is unchanged, and `lance-arrow-scalar` and `lance-arrow-stats` join its dev-dependencies. The CI jobs, the upgrade detector and the Rust agent notes point at `cargo test -p lance --test arrow_ordering` and the new path. Co-Authored-By: Claude Fable 5.1 <[email protected]>
## Summary Define **Zone Write Seeds**: column statistics collected during data-file writes, normally one record per 8,192 rows. These statistics follow [Arrow Rust ordering](https://arrow.apache.org/rust/arrow_ord/sort/fn.sort.html). The table layer can use them for zone pruning, aggregate them for fragment or index segment pruning, or build an index without rereading the column. This is a format proposal. Version 1 seed readers and writers will be implemented separately. The existing ZoneMap index format and query behavior are unchanged. ## What changes - Add `version = "1"` to the seed's Arrow IPC schema metadata. - Store `min` and `max` without nulls or NaNs. Bounds may be wider than the exact extrema but must not exclude values. - Keep exact `null_count` and total `nan_count`; add exact `negative_nan_count` so consumers can distinguish NaN signs. - Keep `zone_length`, the existing seed locator and global-buffer storage, and the optional null bitmap. - Reserve **`FLAG_ZONE_WRITE_SEEDS` (`1 << 16`)** in both dataset reader and writer feature words. The first commit referencing version 1 seeds sets both bits; unsupported clients refuse the dataset. Both bits are retained through later commits, clone, and restore. Existing seeds without version metadata remain version 0. Their NaN sign split is unknown, and their `max` may contain the legacy `+NaN` marker. They must not be relabeled as version 1. ## Documentation [Zone Write Seeds](https://github.com/LuQQiu/lance/blob/ac99e24e4abf4985a67f8d4eb9a70072a5d66cb1/docs/src/format/index/scalar/zone_write_seeds.md) describes the fields, storage, and compatibility rules. It links directly to Arrow Rust documentation rather than defining a separate ordering specification. ## Validation - Documentation build, Rust formatting, normal pre-commit hooks, and `git diff --check` passed. Documentation warnings are existing unrelated links. - This revision changes documentation and flag/test naming; bit values and feature behavior are unchanged. - Rust tests and workspace clippy were not rerun locally: there is no build cache in this worktree and the host has about 44 GiB free, so a cold workspace build risks exhausting disk. CI must validate the revision before merge. Related: [#9810](#9810) adds ordering compatibility tests and dependency-upgrade CI checks. This persisted-format proposal requires a PMC format vote. --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
Why this change?
Lance uses Arrow Rust and DataFusion to compare and sort values. If a dependency upgrade changes those comparisons, it can affect index ordering, column statistics, and query results—even without changing Lance code.
This PR adds fixed tests and a conditional CI check to catch those changes before merging. It covers the root Rust workspace and root
Cargo.lock.What the tests check
The tests live in
rust/lance/tests/arrow_ordering.rs, inside the existinglancecrate. There is no separate test crate.Thirteen typed fixtures have hand-written expected results, covering floats, strings, binary, signed/unsigned integers, dates, timestamps, decimals, and booleans. They exercise:
ArrowScalar, and DataFusion scalar comparison.Float checks compare bit patterns, including signed zero, infinities, and different NaNs. Sorting follows IEEE 754
totalOrder; the statistics accumulator excludes NaNs from min/max and counts them separately.Expectations are not generated from the code being tested. Failures identify the type, comparison path, and expected versus actual result.
When CI runs
The test target has
test = false, so it does not run with the ordinary test suite. CI invokes it explicitly when:halfversions or Git sources/revisions change in the root lockfile.arrow-scalar, orarrow-statschange.CI first runs the base branch's fixtures against the PR's code and dependencies, then runs the PR's fixtures. Changing expectations in the same PR therefore cannot silently hide an ordering change.
A base-fixture failure requires investigation of the affected Lance paths and persisted structures. The
arrow-ordering-reviewedlabel permits a reviewed change; the PR's fixtures must still pass. For this initial PR, the base branch has no fixtures, so only the new copy runs.The detector also produces release-note links and a review checklist. Same-version local path patches are not currently detected.
Scope and verification
rust/AGENTS.mdexplains how to investigate ordering changes.Run the ordering tests manually with:
cargo test -p lance --test arrow_ordering