feat(python): open blob files by row offset (#5356)

Open seekable Blob files by row position with
`table.take_blob_files(column, offsets, *, buffer_size=None)` on
synchronous and asynchronous Embedded and Enterprise tables. Results
follow the requested order, duplicate offsets have independent cursors,
and NULL and empty values stay distinct. An invalid offset rejects the
entire batch.

Enterprise resolves positions and descriptors together and verifies one
snapshot across descriptor queries, location resolution, and
authenticated byte reads. Eligible ranges use the existing presigned
read path when the gateway advertises it.

Refs [OSS-2881](https://linear.app/lancedb/issue/OSS-2881).

## Validation

- On Enterprise 1.16.0, the same locked wheel passed both sync and async
reads of 1,025 distinct offsets after a deletion. The offsets matched an
independent ordered query, and the two descriptor chunks and subsequent
authenticated requests matched the pinned version and snapshot identity.
- Both APIs returned byte-for-byte matches for 37-byte proxy reads and a
32 MiB presigned object-store read. The large reads used zero gateway
byte requests. An independent range check returned two object-store HTTP
206 responses with matching physical ranges and bytes.
- The wheel passed 23 focused Python tests. The Rust library check and
all 81 Enterprise Blob module tests passed, including nested NULL and
strict snapshot echo cases.

Runtime evidence is from commit
`f56c359ba7874cd75c52169491166a941251510f` with Lance `16.0.0-beta.6`,
wheel SHA-256
`9abbbfe584513432547d237dcf7b684b479b35cad07c48cd9899d381f0e80423`. The
merge preview with `main` at `ff556729` is clean.
[#5352](https://github.com/lancedb/lancedb/pull/5352) updates the
integration dependencies to Lance `16.0.0-beta.7` and `object_store`
`0.14.2`. Those pins are outside the tested wheel's coverage.

The synthetic test table was removed from the catalog. Its physical
storage cleanup is tracked separately.
This commit is contained in:
Xuanwo
2026-12-02 12:47:38 +00:00
committed by GitHub
parent eea95c8778
commit 0a14761f0e
13 changed files with 1209 additions and 133 deletions
+51 -16
View File
@@ -1252,7 +1252,7 @@ impl From<lancedb::table::DropColumnsResult> for DropColumnsResult {
}
}
/// Lazy blob handle from ``Table.fetch_blob_files``.
/// Lazy, seekable blob handle.
#[pyclass(name = "BlobFile")]
pub struct PyBlobFile {
inner: Arc<BlobFile>,
@@ -1260,6 +1260,28 @@ pub struct PyBlobFile {
}
impl PyBlobFile {
async fn from_handles(
handles: Vec<Option<BlobFile>>,
buffer_size: Option<usize>,
) -> PyResult<Vec<Option<Self>>> {
if let Some(size) = buffer_size {
for file in handles.iter().flatten() {
file.set_buffer_size(size)
.await
.map_err(|e| blob_file_error("set_buffer_size", e))?;
}
}
Ok(handles
.into_iter()
.map(|handle| {
handle.map(|file| Self {
inner: Arc::new(file),
closed: AtomicBool::new(false),
})
})
.collect())
}
fn ensure_open(&self) -> PyResult<()> {
if self.closed.load(Ordering::Acquire) {
Err(PyRuntimeError::new_err("blob file is already closed"))
@@ -2336,22 +2358,35 @@ impl Table {
.fetch_blob_files(column.as_str(), &row_ids)
.await
.infer_error()?;
if let Some(size) = buffer_size {
for file in handles.iter().flatten() {
file.set_buffer_size(size)
.await
.map_err(|e| blob_file_error("set_buffer_size", e))?;
}
}
Ok(handles
.into_iter()
.map(|handle| {
handle.map(|file| PyBlobFile {
inner: Arc::new(file),
closed: AtomicBool::new(false),
})
PyBlobFile::from_handles(handles, buffer_size).await
})
}
/// Open lazy blob handles by row offset in the visible table snapshot.
#[pyo3(signature = (column, offsets, *, buffer_size=None))]
pub fn take_blob_files(
self_: PyRef<'_, Self>,
column: String,
offsets: Vec<i128>,
buffer_size: Option<usize>,
) -> PyResult<Bound<'_, PyAny>> {
let inner = self_.inner_ref()?.clone();
let offsets = offsets
.into_iter()
.map(|offset| {
u64::try_from(offset).map_err(|_| {
PyValueError::new_err(format!(
"row offset {offset} must be a non-negative 64-bit integer"
))
})
.collect::<Vec<_>>())
})
.collect::<PyResult<Vec<_>>>()?;
future_into_py(self_.py(), async move {
let handles = inner
.take_blob_files(column, &offsets)
.await
.infer_error()?;
PyBlobFile::from_handles(handles, buffer_size).await
})
}