mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
## Summary Add an opt-in `preserve_order` flag to sync and async `take_offsets`. It exposes the existing Rust `TakeRestoreExec` ordering path and carries the flag through `QueryRequest`, `PyQueryRequest`, and the Python `Query` model. ## Behavior - Default `preserve_order=False` keeps the existing incremental, unspecified-order behavior. - `preserve_order=True` returns found rows in input order, including repeated offsets. - Missing non-negative offsets keep filter semantics and are omitted; negative offsets remain rejected by the existing `u64` contract. - Rust take queries apply `limit`/`offset` after order and repetition are restored. Python take builders and Query conversion do not expose pagination. - An explicit `order_by` conflicts with offset `preserve_order` and raises clearly. `take_row_ids` keeps its existing implicit ordering and explicit-sort behavior. - `__getitems__` is unchanged: it keeps its Python re-alignment and strict missing-offset (`ArrowIndexError`) behavior. ## Remote lookup The remote lookup sends only the deduplicated `_rowoffset IN (...)` filter and restores order/repetition client-side; there is no new wire field or backend extension. Namespace take queries stay on local execution, and RTE/LSM rejects the `_rowoffset` lookup loudly. ## Testing - Old reviewed head reproduced the serialization regression: `test_query_serialization_sync/async` failed because the Query model exposed `False` for an unset field. - Fixed by using `Optional[bool] = None` and mapping Rust `false` to absent in `PyQueryRequest`; explicit `True` still survives the actual round trip. - `python/tests/test_query.py`: 253 passed, 1 skipped. - Rust preserve-order tests: 3 passed; row-id/order-by tests: 27 passed. - Remote ordered Blob bytes, remote permutation, and Blob mode focused cases: 3 passed. - `cargo fmt --check`, `ruff format/check`, `py_compile`, and `git diff --check` passed. ## Migration `lancedb::query::QueryRequest` is a public non-`#[non_exhaustive]` struct. Downstream code that constructs it with an exhaustive struct literal must add `preserve_order: false` or use `..Default::default()`. The field is client-side metadata and is not sent over the remote protocol. Seekable Blob APIs, rollout, and ENT-4059 remain separate work. Refs OSS-2881 (non-closing).