perf(python): deduplicate sync query preparation (#5130)

## Summary

Sync query execution rebuilt schema-derived state several times inside
one call: for vector-column inference, blob projection validation,
row-id preparation, async handoff, and result finalization. A plain
point lookup paid five schema reads and five background-loop submissions
per `to_arrow()`.

This change prepares the schema and projected blob sources once per
execution and reuses them through scan setup, result finalization, and
the async handoff. Sync-prepared queries tell the async layer that blob
row ids are already resolved; nothing is cached between executions, so a
reused builder still observes schema changes. Plain scans and explicit
vector columns no longer read the schema just to infer a vector column,
and the dead vector conversion in `LanceVectorQueryBuilder.to_batches()`
is removed.

Non-lazy vector `to_arrow()` stays on its lazy materialization path, so
reranking and snapshot merging run once before the aggregate blob
conversion. Async behavior, namespace routing, fragments, timeouts, and
public APIs are unchanged. A direct synchronous Rust terminal remains
follow-up work.

## Benchmark

Workload: 200,000 rows, 64 dimensions, BTREE on `id`, IVF_PQ on
`vector`; 50 warmups + 500 calls per run; p50 of three runs. Baseline
and candidate Python packages ran against the same `release-no-lto`
extension built at `a2176f9b`; only package source differed. Local NVMe,
single host.

| Workload | Loop/schema per call before -> after | p50 before -> after
|
|---|---|---|
| plain point lookup `to_arrow()` | 5 / 5 -> 2 / 1 | 6.06 / 6.08 / 5.67
ms -> 3.26 / 3.26 / 3.33 ms |
| indexed vector `to_arrow()` | 5 / 5 -> 3 / 2 | 8.82 / 8.21 / 8.35 ms
-> 6.40 / 6.55 / 6.60 ms |
| plain point lookup `to_batches().read_all()` | 6 / 4 -> 4 / 1 | 6.88 /
7.25 / 6.94 ms -> 4.37 / 4.80 / 3.76 ms |

`release-no-lto` is a local comparison build, not a release-profile
number. The branch includes a merge of current main (`a2176f9b`, #5129);
the affected blob, reranker, FTS, query, and namespace checks were rerun
against the merged tree.

Refs OSS-2867 (non-closing).
This commit is contained in:
Xuanwo
2026-11-21 00:49:47 +08:00
committed by GitHub
parent a2176f9bcd
commit 03fc5404ae
6 changed files with 343 additions and 70 deletions
+192 -57
View File
@@ -1105,6 +1105,9 @@ class Query(pydantic.BaseModel):
The default is False
"""
# Internal: the sync query layer already prepared blob row ids.
_blob_row_id_prepared: bool = pydantic.PrivateAttr(default=False)
# The name of the vector column to use for vector search.
vector_column: Optional[str] = None
@@ -1770,23 +1773,85 @@ class LanceQueryBuilder(ABC):
def _user_requested_row_id(self) -> bool:
return self._with_row_id is True
def _blob_auto_row_id_enabled(self) -> bool:
def _blob_auto_row_id_enabled(self, schema: Optional[pa.Schema] = None) -> bool:
if self._with_row_id is not None:
return False
if schema is None:
schema = self._table.schema
return blob_auto_row_id_for_scan(
self._table.schema,
schema,
self._columns,
with_row_id=self._with_row_id,
)
def _scan_needs_row_id(self) -> bool:
return self._user_requested_row_id() or self._blob_auto_row_id_enabled()
def _row_id_schema(self) -> Optional[pa.Schema]:
if self._with_row_id is not None:
return None
return self._table.schema
def _query_for_scan(self, blob_sources: Optional[dict[str, str]] = None) -> Query:
def _scan_needs_row_id(self, schema: Optional[pa.Schema] = None) -> bool:
if self._user_requested_row_id():
return True
return self._blob_auto_row_id_enabled(schema)
def _query_for_scan(
self,
blob_sources: Optional[dict[str, str]] = None,
schema: Optional[pa.Schema] = None,
) -> Query:
self._ensure_fragment_constraints_supported("this query")
query = self.to_query_object()
if self._scan_needs_row_id() or blob_sources:
if schema is None:
schema = self._row_id_schema()
if self._scan_needs_row_id(schema) or blob_sources:
query.with_row_id = True
return query
def _prepare_blob_execution(
self, blob_mode: BlobMode
) -> tuple[dict[str, str], Optional[pa.Schema]]:
validate_blob_mode(blob_mode)
schema = self._table.schema
if blob_mode == "lazy":
if not schema_has_blob_field(schema):
return {}, schema
# Lazy results hide automatic row ids inside projected blob columns.
return blob_v2_projection_sources(schema, self._columns), schema
return self._validated_blob_sources(blob_mode, schema), schema
def _to_batches_prepared(
self,
*,
batch_size: Optional[int],
timeout: Optional[timedelta],
blob_mode: BlobMode,
blob_sources: dict[str, str],
schema: Optional[pa.Schema],
) -> pa.RecordBatchReader:
query = self._query_for_scan(blob_sources, schema)
reader = self._execute_query_prepared(
query, batch_size=batch_size, timeout=timeout
)
return self._batches_in_mode(reader, blob_mode, blob_sources, schema)
def _execute_query_prepared(
self,
query: Query,
*,
batch_size: Optional[int] = None,
timeout: Optional[timedelta] = None,
) -> pa.RecordBatchReader:
if not _is_remote_query_table(self._table):
query._blob_row_id_prepared = True
return self._table._execute_query(query, batch_size=batch_size, timeout=timeout)
def _execute_arrow_prepared(
self, query: Query, *, timeout: Optional[timedelta] = None
) -> pa.Table:
if not _is_remote_query_table(self._table):
query._blob_row_id_prepared = True
return self._table._execute_arrow(query, timeout=timeout)
def _ensure_fragment_constraints_supported(self, operation: str) -> None:
_raise_unsupported_fragment_constraints(
self._fragments,
@@ -1812,13 +1877,18 @@ class LanceQueryBuilder(ABC):
)
)
def _validated_blob_sources(self, blob_mode: BlobMode) -> dict[str, str]:
def _validated_blob_sources(
self, blob_mode: BlobMode, schema: Optional[pa.Schema] = None
) -> dict[str, str]:
"""Map projected blob outputs to their source columns.
Bytes mode is checked here, before the query runs.
"""
validate_blob_mode(blob_mode)
schema = self._table.schema
if blob_mode == "lazy":
return {}
if schema is None:
schema = self._table.schema
blob_sources = blob_projection_sources(
schema,
self._columns,
@@ -1866,8 +1936,9 @@ class LanceQueryBuilder(ABC):
*,
blob_mode: BlobMode,
blob_sources: dict[str, str],
schema: Optional[pa.Schema] = None,
) -> pa.Table:
blob_auto_row_id = self._blob_auto_row_id_enabled()
blob_auto_row_id = self._blob_auto_row_id_enabled(schema)
if blob_mode == "bytes" and blob_sources:
# Bytes conversion reads _rowid directly, including when the
# projection mixes legacy and v2 columns.
@@ -1895,22 +1966,26 @@ class LanceQueryBuilder(ABC):
reader: pa.RecordBatchReader,
blob_mode: BlobMode,
blob_sources: dict[str, str],
schema: Optional[pa.Schema] = None,
) -> pa.RecordBatchReader:
if blob_mode == "lazy":
return reader
def convert(tbl: pa.Table) -> pa.Table:
return self._finalize_blob_query_table(
tbl, blob_mode=blob_mode, blob_sources=blob_sources
tbl,
blob_mode=blob_mode,
blob_sources=blob_sources,
schema=schema,
)
schema = convert(pa.Table.from_batches([], schema=reader.schema)).schema
result_schema = convert(pa.Table.from_batches([], schema=reader.schema)).schema
def batches():
for batch in reader:
yield from convert(pa.Table.from_batches([batch])).to_batches()
return pa.RecordBatchReader.from_batches(schema, batches())
return pa.RecordBatchReader.from_batches(result_schema, batches())
def with_row_address(self, with_row_address: bool = True) -> Self:
"""Set whether to return row addresses.
@@ -2547,17 +2622,26 @@ class LanceVectorQueryBuilder(LanceQueryBuilder):
``"bytes"`` returns payload bytes for supported row-addressable blob
columns and raises for blobs inside lists.
"""
blob_sources = self._validated_blob_sources(blob_mode)
blob_sources, schema = self._prepare_blob_execution(blob_mode)
if blob_mode != "lazy":
# Materialize in lazy mode so reranking runs once over the full
# result before the requested aggregate blob conversion.
return self._finalize_blob_query_table(
self.to_batches(timeout=timeout).read_all(),
self._to_batches_prepared(
batch_size=None,
timeout=timeout,
blob_mode="lazy",
blob_sources=blob_sources,
schema=schema,
).read_all(),
blob_mode=blob_mode,
blob_sources=blob_sources,
schema=schema,
)
self._ensure_fragment_constraints_supported("to_arrow()")
results = self._table._execute_arrow(
self._query_for_scan(blob_sources), timeout=timeout
results = self._execute_arrow_prepared(
self._query_for_scan(blob_sources, schema), timeout=timeout
)
if self._reranker is not None:
source = results
@@ -2565,7 +2649,10 @@ class LanceVectorQueryBuilder(LanceQueryBuilder):
check_reranker_result(results)
results = _merge_query_snapshot(results, source)
return self._finalize_blob_query_table(
results, blob_mode=blob_mode, blob_sources=blob_sources
results,
blob_mode=blob_mode,
blob_sources=blob_sources,
schema=schema,
)
def to_query_object(self) -> Query:
@@ -2605,6 +2692,31 @@ class LanceVectorQueryBuilder(LanceQueryBuilder):
order_by=self._order_by,
)
def _to_batches_prepared(
self,
*,
batch_size: Optional[int],
timeout: Optional[timedelta],
blob_mode: BlobMode,
blob_sources: dict[str, str],
schema: Optional[pa.Schema],
) -> pa.RecordBatchReader:
query = self._query_for_scan(blob_sources, schema)
result_set = self._execute_query_prepared(
query, batch_size=batch_size, timeout=timeout
)
if self._reranker is not None:
rs_table = result_set.read_all()
result_set = self._reranker.rerank_vector(self._str_query, rs_table)
check_reranker_result(result_set)
result_set = _merge_query_snapshot(result_set, rs_table)
# convert result_set back to RecordBatchReader
result_set = pa.RecordBatchReader.from_batches(
result_set.schema, result_set.to_batches()
)
return self._batches_in_mode(result_set, blob_mode, blob_sources, schema)
def to_batches(
self,
/,
@@ -2633,25 +2745,14 @@ class LanceVectorQueryBuilder(LanceQueryBuilder):
-------
pa.RecordBatchReader
"""
blob_sources = self._validated_blob_sources(blob_mode)
vector = self._query if isinstance(self._query, list) else self._query.tolist()
if isinstance(vector[0], np.ndarray):
vector = [v.tolist() for v in vector]
query = self._query_for_scan(blob_sources)
result_set = self._table._execute_query(
query, batch_size=batch_size, timeout=timeout
blob_sources, schema = self._prepare_blob_execution(blob_mode)
return self._to_batches_prepared(
batch_size=batch_size,
timeout=timeout,
blob_mode=blob_mode,
blob_sources=blob_sources,
schema=schema,
)
if self._reranker is not None:
rs_table = result_set.read_all()
result_set = self._reranker.rerank_vector(self._str_query, rs_table)
check_reranker_result(result_set)
result_set = _merge_query_snapshot(result_set, rs_table)
# convert result_set back to RecordBatchReader
result_set = pa.RecordBatchReader.from_batches(
result_set.schema, result_set.to_batches()
)
return self._batches_in_mode(result_set, blob_mode, blob_sources)
def where(
self, where: Union[str, Expr], prefilter: bool = None
@@ -2887,22 +2988,25 @@ class LanceFtsQueryBuilder(LanceQueryBuilder):
timeout: Optional[timedelta] = None,
blob_mode: BlobMode = "lazy",
) -> pa.Table:
blob_sources = self._validated_blob_sources(blob_mode)
blob_sources, schema = self._prepare_blob_execution(blob_mode)
self._table._ensure_no_legacy_fts_index()
self._ensure_fragment_constraints_supported("to_arrow()")
query = self._query_for_scan(blob_sources)
query = self._query_for_scan(blob_sources, schema)
if blob_mode == "lazy":
results = self._table._execute_arrow(query, timeout=timeout)
results = self._execute_arrow_prepared(query, timeout=timeout)
else:
results = self._table._execute_query(query, timeout=timeout).read_all()
results = self._execute_query_prepared(query, timeout=timeout).read_all()
if self._reranker is not None:
source = results
results = self._reranker.rerank_fts(self._query, results)
check_reranker_result(results)
results = _merge_query_snapshot(results, source)
return self._finalize_blob_query_table(
results, blob_mode=blob_mode, blob_sources=blob_sources
results,
blob_mode=blob_mode,
blob_sources=blob_sources,
schema=schema,
)
def to_batches(
@@ -2941,23 +3045,37 @@ class LanceEmptyQueryBuilder(LanceQueryBuilder):
timeout: Optional[timedelta] = None,
blob_mode: BlobMode = "lazy",
) -> pa.Table:
blob_sources = self._validated_blob_sources(blob_mode)
blob_sources, schema = self._prepare_blob_execution(blob_mode)
if blob_mode == "bytes" and blob_sources:
return self.to_batches(timeout=timeout, blob_mode=blob_mode).read_all()
return self._to_batches_prepared(
batch_size=None,
timeout=timeout,
blob_mode="bytes",
blob_sources=blob_sources,
schema=schema,
).read_all()
if blob_mode != "lazy":
return self._finalize_blob_query_table(
self.to_batches(timeout=timeout).read_all(),
self._to_batches_prepared(
batch_size=None,
timeout=timeout,
blob_mode="lazy",
blob_sources=blob_sources,
schema=schema,
).read_all(),
blob_mode=blob_mode,
blob_sources=blob_sources,
schema=schema,
)
self._ensure_fragment_constraints_supported("to_arrow()")
return self._finalize_blob_query_table(
self._table._execute_arrow(
self._query_for_scan(blob_sources), timeout=timeout
self._execute_arrow_prepared(
self._query_for_scan(blob_sources, schema), timeout=timeout
),
blob_mode=blob_mode,
blob_sources=blob_sources,
schema=schema,
)
def to_query_object(self) -> Query:
@@ -2986,12 +3104,14 @@ class LanceEmptyQueryBuilder(LanceQueryBuilder):
*,
blob_mode: BlobMode = "lazy",
) -> pa.RecordBatchReader:
blob_sources = self._validated_blob_sources(blob_mode)
query = self._query_for_scan(blob_sources)
reader = self._table._execute_query(
query, batch_size=batch_size, timeout=timeout
blob_sources, schema = self._prepare_blob_execution(blob_mode)
return self._to_batches_prepared(
batch_size=batch_size,
timeout=timeout,
blob_mode=blob_mode,
blob_sources=blob_sources,
schema=schema,
)
return self._batches_in_mode(reader, blob_mode, blob_sources)
def rerank(self, reranker: Reranker) -> LanceEmptyQueryBuilder:
"""Rerank the results using the specified reranker.
@@ -3136,11 +3256,14 @@ class LanceHybridQueryBuilder(LanceQueryBuilder):
timeout: Optional[timedelta] = None,
blob_mode: BlobMode = "lazy",
) -> pa.Table:
blob_sources = self._validated_blob_sources(blob_mode)
blob_sources, schema = self._prepare_blob_execution(blob_mode)
# WAL-PK-FUSION: without the fallback, this body is `_run_hybrid`'s.
return _wal_hybrid.with_pk_fallback(
lambda: self._run_hybrid(
timeout=timeout, blob_mode=blob_mode, blob_sources=blob_sources
timeout=timeout,
blob_mode=blob_mode,
blob_sources=blob_sources,
schema=schema,
),
self._table,
fused=lambda: self._pk_fusion is not None,
@@ -3153,6 +3276,7 @@ class LanceHybridQueryBuilder(LanceQueryBuilder):
timeout: Optional[timedelta] = None,
blob_mode: BlobMode,
blob_sources: dict[str, str],
schema: Optional[pa.Schema],
) -> pa.Table:
self._create_query_builders()
fts_query, vector_query = self._fts_query, self._vector_query
@@ -3182,7 +3306,10 @@ class LanceHybridQueryBuilder(LanceQueryBuilder):
)
results = _merge_query_snapshot(results, fts_results, vector_results)
return self._finish_hybrid_results(
results, blob_mode=blob_mode, blob_sources=blob_sources
results,
blob_mode=blob_mode,
blob_sources=blob_sources,
schema=schema,
)
def _finish_hybrid_results(
@@ -3191,6 +3318,7 @@ class LanceHybridQueryBuilder(LanceQueryBuilder):
*,
blob_mode: BlobMode,
blob_sources: dict[str, str],
schema: Optional[pa.Schema],
) -> pa.Table:
if self._pk_fusion is not None: # WAL-PK-FUSION: delete.
return self._apply_arrow_blob_mode(
@@ -3198,9 +3326,12 @@ class LanceHybridQueryBuilder(LanceQueryBuilder):
)
if self._user_requested_row_id():
return self._apply_arrow_blob_mode(results, blob_mode, blob_sources)
if self._blob_auto_row_id_enabled():
if self._blob_auto_row_id_enabled(schema):
return self._finalize_blob_query_table(
results, blob_mode=blob_mode, blob_sources=blob_sources
results,
blob_mode=blob_mode,
blob_sources=blob_sources,
schema=schema,
)
if "_rowid" in results.column_names:
# Fetch bytes before dropping _rowid.
@@ -3834,6 +3965,8 @@ class AsyncQueryBase(object):
self._with_row_id = None
self._blob_auto_row_id = False
self._blob_paths: tuple[str, ...] = ()
# Set by the sync table path, which has already prepared blob row ids.
self._blob_row_id_prepared = False
def to_query_object(self) -> Query:
"""
@@ -4078,7 +4211,8 @@ class AsyncQueryBase(object):
) -> pa.Table:
"""Execute with the native eager collector used by ``to_arrow``."""
self._ensure_fragment_constraints_supported("to_arrow()")
await self._maybe_add_blob_row_id()
if not self._blob_row_id_prepared:
await self._maybe_add_blob_row_id()
reader = await self._inner.execute_to_reader(None, timeout)
return pa.Table.from_batches(reader, schema=reader.schema)
@@ -4106,7 +4240,8 @@ class AsyncQueryBase(object):
max_batch_length=max_batch_length,
timeout=timeout,
)
await self._maybe_add_blob_row_id()
if not self._blob_row_id_prepared:
await self._maybe_add_blob_row_id()
return AsyncRecordBatchReader(
await self._inner.execute(
max_batch_length=max_batch_length, timeout=timeout
+12 -1
View File
@@ -5747,8 +5747,16 @@ class LanceTable(Table):
"""
if isinstance(query, FullTextQuery):
query_type = "fts"
if (
vector_column_name is None
and query_type != "fts"
and not (query is None and query_type != "hybrid")
):
schema = self.schema
else:
schema = None
vector_column_name = infer_vector_column_name(
schema=self.schema,
schema=schema,
query_type=query_type,
query=query,
vector_column_name=vector_column_name,
@@ -6033,6 +6041,7 @@ class LanceTable(Table):
return self._execute_query(query, timeout=timeout).read_all()
async_query = self._table._sync_query_to_async(query)
async_query._blob_row_id_prepared = query._blob_row_id_prepared
return LOOP.run(async_query._execute_eager(timeout=timeout))
def _explain_plan(self, query: Query, verbose: Optional[bool] = False) -> str:
@@ -8547,6 +8556,7 @@ class AsyncTable:
# used for that code path right now.
async_query = self._sync_query_to_async(query)
async_query._blob_row_id_prepared = query._blob_row_id_prepared
return await async_query.to_batches(
max_batch_length=batch_size, timeout=timeout
@@ -8568,6 +8578,7 @@ class AsyncTable:
return (await self._execute_query(query, timeout=timeout)).read_all()
async_query = self._sync_query_to_async(query)
async_query._blob_row_id_prepared = query._blob_row_id_prepared
return await async_query._execute_eager(timeout=timeout)
async def _explain_plan(self, query: Query, verbose: Optional[bool]) -> str:
+3 -1
View File
@@ -328,7 +328,7 @@ def _query_vector_dim(query: Optional[Any]) -> Optional[int]:
def infer_vector_column_name(
schema: pa.Schema,
schema: Optional[pa.Schema],
query_type: str,
query: Optional[Any], # inferred later in query builder
vector_column_name: Optional[str],
@@ -348,6 +348,8 @@ def infer_vector_column_name(
# nothing to infer.
return None
if schema is None:
raise ValueError("schema is required to infer a vector column")
vector_column_name = inf_vector_column_query(schema, dim=_query_vector_dim(query))
if vector_column_name is None:
+71
View File
@@ -2399,6 +2399,77 @@ class _KeepAllScoresReranker(Reranker):
return combined.append_column("_relevance_score", scores)
class _RecordingVectorReranker(Reranker):
def __init__(self):
super().__init__(return_score="all")
self.calls = []
def rerank_hybrid(self, query, vector_results, fts_results):
raise AssertionError("vector queries must not call rerank_hybrid")
def rerank_vector(self, query, vector_results):
self.calls.append((query, vector_results))
return vector_results.append_column(
"_relevance_score",
pa.array([1.0] * len(vector_results), type=pa.float32()),
)
@pytest.mark.parametrize("blob_mode", ["descriptions", "bytes"])
def test_vector_to_arrow_reranks_before_blob_conversion(blob_mode, monkeypatch):
db = lancedb.connect("memory:///")
schema = pa.schema(
[
pa.field("id", pa.int64()),
pa.field("vector", pa.list_(pa.float32(), list_size=2)),
lancedb.blob("image"),
]
)
table = db.create_table(f"vector_rerank_{blob_mode}", schema=schema)
rows = 1100
table.add(
[
{
"id": row_id,
"vector": [1.0, float(row_id % 2)],
"image": f"image-{row_id}".encode(),
}
for row_id in range(rows)
]
)
fetched = []
fetch_blobs = table.fetch_blobs
def fetch(column, row_ids):
fetched.append((column, len(row_ids)))
return fetch_blobs(column, row_ids)
monkeypatch.setattr(table, "fetch_blobs", fetch)
reranker = _RecordingVectorReranker()
hits = (
table.search([1.0, 0.0])
.limit(rows)
.select(["id", "image"])
.rerank(reranker, "hello")
.to_arrow(blob_mode=blob_mode)
)
assert len(reranker.calls) == 1
query, source = reranker.calls[0]
assert query == "hello"
# The reranker sees descriptors, not already-converted payload bytes.
assert not pa.types.is_large_binary(source.schema.field("image").type)
assert "_relevance_score" in hits.column_names
assert len(hits) == rows
if blob_mode == "bytes":
# The whole lazy result is materialized before one aggregate conversion.
assert fetched == [("image", rows)]
assert pa.types.is_large_binary(hits.schema.field("image").type)
else:
assert fetched == []
assert not pa.types.is_large_binary(hits.schema.field("image").type)
def test_bytes_mode_rejects_legacy_blob_after_reranker_drops_metadata(tmp_path):
db = lancedb.connect(tmp_path)
table = db.create_table(
+64 -10
View File
@@ -1739,17 +1739,16 @@ def test_query_builder_with_different_vector_column():
ds = mock.Mock()
table.to_lance.return_value = ds
builder.to_arrow()
table._execute_arrow.assert_called_once_with(
Query(
vector=query,
filter="b < 10",
limit=2,
distance_type="cosine",
columns=["b"],
vector_column="foo_vector",
),
timeout=None,
expected = Query(
vector=query,
filter="b < 10",
limit=2,
distance_type="cosine",
columns=["b"],
vector_column="foo_vector",
)
expected._blob_row_id_prepared = True
table._execute_arrow.assert_called_once_with(expected, timeout=None)
def cosine_distance(vec1, vec2):
@@ -2657,6 +2656,61 @@ def test_query_schema(tmp_path):
)
def test_sync_query_prepares_schema_once_per_execution(tmp_path, monkeypatch):
db = lancedb.connect(tmp_path)
table = db.create_table(
"test",
pa.table(
{
"id": [1, 2, 3],
"vector": pa.array(
[[1, 2], [3, 4], [5, 6]],
pa.list_(pa.float32(), list_size=2),
),
}
),
)
calls = 0
original = AsyncTable.schema
async def counted(self):
nonlocal calls
calls += 1
return await original(self)
monkeypatch.setattr(AsyncTable, "schema", counted)
table.search().where("id = 1").select(["id"]).to_arrow()
assert calls <= 1
calls = 0
table.search([1, 2], vector_column_name="vector").limit(1).to_arrow()
assert calls <= 1
calls = 0
table.search([1, 2]).limit(1).to_arrow()
# At most one lookup infers the vector column, one prepares execution.
assert calls <= 2
calls = 0
table.search().where("id = 1").select(["id"]).to_batches().read_all()
assert calls <= 1
builder = table.search().where("id = 1")
before = builder.to_arrow()
assert "extra" not in before.column_names
assert "image" not in before.column_names
table.add_columns(pa.schema([pa.field("extra", pa.int64()), lancedb.blob("image")]))
calls = 0
after = builder.to_arrow()
assert calls <= 1
assert after["extra"].to_pylist() == [None]
assert "_lance_row_id" in str(after.schema)
assert "_rowid" not in after.column_names
@pytest.mark.asyncio
async def test_query_schema_async(tmp_path):
db = await lancedb.connect_async(tmp_path)
+1 -1
View File
@@ -120,7 +120,7 @@ def test_wal_hybrid_fuses_on_the_key_and_drops_it_again():
with_row_ids=True,
)
results = builder._finish_hybrid_results(
combined, blob_mode="lazy", blob_sources={}
combined, blob_mode="lazy", blob_sources={}, schema=None
)
assert "_rowid" not in results.column_names, "the surrogate is internal"