mirror of
https://github.com/lancedb/lancedb.git
synced 2026-09-06 05:19:02 +00:00
fix: stop enabling stable row ids on blob table create (#4126)
This PR stops blob table create from implicitly enabling stable row ids. A blob schema still selects Lance file format 2.2, but row id behavior stays with the table config. Compact then fetch with a `_rowid` captured before compaction is still not supported on a default table. That needs `take` to remap row addresses through blob reuse rather than making stable row ids a blob-table default. BREAKING CHANGE: blob create no longer enables stable row ids. A blob schemastill selects Lance file format 2.2. Fetch uses `_rowid` on HEAD. Held ids survive compact only when the table has stable row ids. ## Testing * `cargo fmt --all` * `ruff format .` * `ruff check .` * `cargo clippy --quiet --features remote --tests --examples -p lancedb` * `cargo test --quiet --features remote -p lancedb --test blob_integration` * `python/.venv/bin/pytest python/python/tests/test_blob.py -q`
This commit is contained in:
@@ -1793,6 +1793,9 @@ class Table(ABC):
|
||||
The result has the same length and order as ``row_ids``. Null blobs
|
||||
produce null slots; valid empty blobs produce ``b""``.
|
||||
|
||||
``_rowid`` values stay valid after compaction when the table has stable
|
||||
row ids.
|
||||
|
||||
Convenience for small payloads. For large values use
|
||||
:meth:`fetch_blob_files`.
|
||||
"""
|
||||
@@ -1810,6 +1813,9 @@ class Table(ABC):
|
||||
The result has the same length and order as ``requests``; null blobs
|
||||
produce null slots and empty ranges on non-null blobs produce ``b""``.
|
||||
|
||||
``_rowid`` values stay valid after compaction when the table has stable
|
||||
row ids.
|
||||
|
||||
Row IDs can be obtained from a query with ``with_row_id(True)``. This
|
||||
API is currently supported only by local tables.
|
||||
"""
|
||||
@@ -1825,6 +1831,9 @@ class Table(ABC):
|
||||
``_rowid`` or a ``_lance_row_id`` field on the blob descriptor. Null
|
||||
rows are ``None``. Remote tables require LanceDB Cloud server 0.5.0 or
|
||||
newer.
|
||||
|
||||
``_rowid`` values stay valid after compaction when the table has stable
|
||||
row ids.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
|
||||
@@ -66,6 +66,25 @@ def _row_ids_by_id(table):
|
||||
return dict(zip(hits["id"].to_pylist(), hits["_rowid"].to_pylist()))
|
||||
|
||||
|
||||
def _assert_missing_blob_row_ids(exc_info):
|
||||
message = str(exc_info.value)
|
||||
assert "row ids" in message
|
||||
assert "rowaddr" not in message
|
||||
assert "fragment" not in message
|
||||
|
||||
|
||||
def _assert_fetch_apis_reject_missing_row_ids(table, row_ids):
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
table.fetch_blobs("image", row_ids)
|
||||
_assert_missing_blob_row_ids(exc_info)
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
table.fetch_blob_files("image", row_ids)
|
||||
_assert_missing_blob_row_ids(exc_info)
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
table.fetch_blob_ranges("image", [(row_id, 0, 1) for row_id in row_ids])
|
||||
_assert_missing_blob_row_ids(exc_info)
|
||||
|
||||
|
||||
def test_blob_factory_declares_v2_field():
|
||||
field = lancedb.blob("image")
|
||||
assert isinstance(field.type, pa.ExtensionType)
|
||||
@@ -691,6 +710,25 @@ def test_fetch_blobs_accepts_query_result():
|
||||
assert {blobs[i].as_py() for i in range(len(blobs))} == {b"gamma"}
|
||||
|
||||
|
||||
def test_fetch_blobs_after_compact_with_stable_row_ids(tmp_path):
|
||||
db = lancedb.connect(
|
||||
tmp_path, storage_options={"new_table_enable_stable_row_ids": "true"}
|
||||
)
|
||||
schema = pa.schema([pa.field("id", pa.int64()), lancedb.blob("image")])
|
||||
table = db.create_table("t", schema=schema)
|
||||
table.add([{"id": 1, "image": b"frag-one"}])
|
||||
table.add([{"id": 2, "image": b"frag-two"}])
|
||||
by_id = _row_ids_by_id(table)
|
||||
ids = [by_id[1], by_id[2]]
|
||||
|
||||
table.optimize()
|
||||
|
||||
blobs = table.fetch_blobs("image", ids)
|
||||
assert blobs.to_pylist() == [b"frag-one", b"frag-two"]
|
||||
ranges = table.fetch_blob_ranges("image", [(ids[0], 5, 3), (ids[1], 5, 3)])
|
||||
assert ranges.to_pylist() == [b"one", b"two"]
|
||||
|
||||
|
||||
def test_fetch_blobs_preserves_null_and_empty_values():
|
||||
table = _blob_table(
|
||||
"nulls",
|
||||
@@ -739,8 +777,25 @@ def test_fetch_blob_ranges_validates_requests():
|
||||
with pytest.raises(ValueError, match="offset \\+ length overflowed"):
|
||||
table.fetch_blob_ranges("image", [(row_id, 2**64 - 1, 1)])
|
||||
|
||||
with pytest.raises(ValueError, match="row IDs"):
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
table.fetch_blob_ranges("image", [(2**64 - 1, 0, 1)])
|
||||
_assert_missing_blob_row_ids(exc_info)
|
||||
|
||||
|
||||
def test_fetch_blob_apis_reject_missing_fragment_row_addr():
|
||||
table = _blob_table("missing_frag", [{"id": 1, "image": b"x"}])
|
||||
live = _row_ids_by_id(table)[1]
|
||||
_assert_fetch_apis_reject_missing_row_ids(table, [1 << 32, live])
|
||||
|
||||
|
||||
def test_fetch_blob_apis_reject_deleted_row_ids():
|
||||
table = _blob_table(
|
||||
"deleted_rows",
|
||||
[{"id": 1, "image": b"one"}, {"id": 2, "image": b"two"}],
|
||||
)
|
||||
by_id = _row_ids_by_id(table)
|
||||
table.delete("id = 2")
|
||||
_assert_fetch_apis_reject_missing_row_ids(table, [by_id[2], by_id[1]])
|
||||
|
||||
|
||||
def test_fetch_blob_ranges_empty_requests_returns_empty_array():
|
||||
|
||||
Reference in New Issue
Block a user