Skip to content

test: pin the Arrow ordering contract with a CI-gated lance-compat crate - #9810

Merged
LuQQiu merged 2 commits into
mainfrom
lance-compat/arrow-ordering
Oct 13, 2026
Merged

LuQQiu merged 2 commits into
mainfrom
lance-compat/arrow-ordering

Conversation

@LuQQiu

@LuQQiu LuQQiu commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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 existing lance crate. 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:

  • Arrow sorting and row encoding, with ascending/descending order and nulls first/last.
  • Arrow comparators, Lance ArrowScalar, and DataFusion scalar comparison.
  • DataFusion sorting, TopK, and merging sorted streams.
  • Lance statistics collection and merging.

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:

  • Arrow, DataFusion, or half versions or Git sources/revisions change in the root lockfile.
  • The fixtures, their Cargo configuration, detector/workflow, arrow-scalar, or arrow-stats change.

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-reviewed label 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

  • No production behavior, file-format, or protobuf changes.
  • Clippy explicitly checks the otherwise-excluded test target.
  • rust/AGENTS.md explains how to investigate ordering changes.
  • 17 ordering tests pass, including six signed-zero statistics cases.
  • 23 detector tests pass.
  • Ordering compatibility, format, clippy, and packaging CI checks pass.

Run the ordering tests manually with:

cargo test -p lance --test arrow_ordering

@github-actions github-actions Bot added A-deps Dependency updates A-ci CI / build workflows chore labels Oct 8, 2026
@LuQQiu
LuQQiu force-pushed the lance-compat/arrow-ordering branch 2 times, most recently from d9e4f9d to 0a49db5 Compare October 10, 2026 02:11
@LuQQiu
LuQQiu force-pushed the lance-compat/arrow-ordering branch from 0a49db5 to 4edfe46 Compare October 10, 2026 02:23
@LuQQiu
LuQQiu marked this pull request as ready for review October 10, 2026 02:23

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

@LuQQiu LuQQiu changed the title test: add lance-compat crate pinning the Arrow ordering contract test: pin the Arrow ordering contract with a CI-gated lance-compat crate Oct 10, 2026
@LuQQiu
LuQQiu force-pushed the lance-compat/arrow-ordering branch from 4edfe46 to 6c809b9 Compare October 10, 2026 02:28
@LuQQiu

LuQQiu commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Correction: the red Python Compatibility Tests check was a main-branch issue that has since been fixed there, not a missing wheel as I first wrote.

The 14.0.0b10 cases failed because the compat harness's pip install pylance==14.0.0b10 needed lance-namespace 0.13, which main added in e85fab2 (#9850). That landed after this PR's last CI run, which is why later PRs such as #9860 pass the job and this one did not.

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: Detect Arrow ordering-relevant changes (run=true), Arrow ordering compatibility (17 passed), clippy including the explicit fixture lint, linux-build and the publishable check.

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 10, 2026
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.
@LuQQiu
LuQQiu force-pushed the lance-compat/arrow-ordering branch from 6c809b9 to 9b03cdc Compare October 10, 2026 17:28
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 10, 2026

@lance-gatekeeper lance-gatekeeper Bot 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.

✅ 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.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 10, 2026

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

Comment thread rust/lance-compat/src/lib.rs Outdated
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright The Lance Authors

//! Compatibility fixtures for the upstream contracts Lance inherits.

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 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"?

Comment on lines +6 to +11
//! 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.

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 there a concern that Arrow might change its ordering rules? That seems pretty unlikely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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]>
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 12, 2026
@LuQQiu
LuQQiu merged commit 8d08f7e into main Oct 13, 2026
@LuQQiu
LuQQiu deleted the lance-compat/arrow-ordering branch October 13, 2026 03:02
LuQQiu added a commit that referenced this pull request Oct 16, 2026
## 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ci CI / build workflows A-deps Dependency updates chore

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants