mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-28 13:33:59 +00:00
feat(nodejs): open source-bearing blob descriptors (#5238)
Add `Table.openBlobFile` and `Table.openBlobFiles` for source-bearing SQL `blob_descriptor` results, matching the existing Rust and Python APIs. The TypeScript methods forward the descriptor to the shared Rust opener instead of reimplementing routing. That keeps the 10 MiB direct-read threshold, pinned snapshot identity, resolver refresh, and 503 single-shot proxy fallback identical to `fetchBlobFiles` and the other public Blob V2 entries. Descriptor fields remain the snake_case shape returned by Arrow/SQL; the wrapper converts unsigned 64-bit values to `bigint` at the NAPI boundary and returns `null` for null descriptors. Existing custom `Table` subclasses keep working through a default "not supported" implementation. Validation: - `pnpm tsc` - `pnpm lint` - `pnpm test --runInBand __test__/blob_open.test.ts __test__/blob_ranges.test.ts __test__/remote_blob_snapshot.test.ts` — 65 passed - focused Rust core tests for direct opens, threshold routing, snapshot preservation, and 503 fallback — passed The docs also update the TypeScript cross-row range table and example; `fetchBlobRanges` was already implemented but was still documented as unavailable.
This commit is contained in:
+55
-2
@@ -8,13 +8,66 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use arrow_array::{Array, LargeBinaryArray};
|
||||
use futures::future::abortable;
|
||||
use lancedb::blob::BlobFile as LanceBlobFile;
|
||||
use lancedb::blob::{
|
||||
BlobDescriptor as LanceBlobDescriptor, BlobDescriptorSource as LanceBlobDescriptorSource,
|
||||
BlobFile as LanceBlobFile,
|
||||
};
|
||||
use napi::Env;
|
||||
use napi::bindgen_prelude::*;
|
||||
use napi_derive::napi;
|
||||
|
||||
use crate::error::convert_error;
|
||||
|
||||
#[napi(object)]
|
||||
pub struct BlobDescriptorInputSource {
|
||||
pub uri: String,
|
||||
pub version: BigInt,
|
||||
pub committed_at_micros: BigInt,
|
||||
pub branch: Option<String>,
|
||||
pub column: String,
|
||||
pub row_reference: BigInt,
|
||||
pub row_is_address: bool,
|
||||
}
|
||||
|
||||
#[napi(object)]
|
||||
pub struct BlobDescriptorInput {
|
||||
pub kind: u32,
|
||||
pub position: BigInt,
|
||||
pub size: BigInt,
|
||||
pub blob_id: u32,
|
||||
pub blob_uri: String,
|
||||
pub source: BlobDescriptorInputSource,
|
||||
}
|
||||
|
||||
impl BlobDescriptorInput {
|
||||
pub(crate) fn into_descriptor(self) -> napi::Result<LanceBlobDescriptor> {
|
||||
Ok(LanceBlobDescriptor {
|
||||
kind: u8::try_from(self.kind).map_err(|_| {
|
||||
napi::Error::from_reason("blob descriptor kind must be between 0 and 255")
|
||||
})?,
|
||||
position: parse_u64(self.position, "blob descriptor position")?,
|
||||
size: parse_u64(self.size, "blob descriptor size")?,
|
||||
blob_id: self.blob_id,
|
||||
blob_uri: self.blob_uri,
|
||||
source: LanceBlobDescriptorSource {
|
||||
uri: self.source.uri,
|
||||
version: parse_u64(self.source.version, "blob descriptor source version")?,
|
||||
committed_at_micros: parse_u64(
|
||||
self.source.committed_at_micros,
|
||||
"blob descriptor source committed_at_micros",
|
||||
)?,
|
||||
branch: self.source.branch,
|
||||
column: self.source.column,
|
||||
row_reference: parse_u64(
|
||||
self.source.row_reference,
|
||||
"blob descriptor source row_reference",
|
||||
)?,
|
||||
row_is_address: self.source.row_is_address,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[napi(object)]
|
||||
pub struct BlobRange {
|
||||
pub start: BigInt,
|
||||
@@ -202,7 +255,7 @@ fn bigint_range(start: BigInt, end: BigInt) -> napi::Result<Range<u64>> {
|
||||
Ok(start..end)
|
||||
}
|
||||
|
||||
fn parse_u64(value: BigInt, name: &str) -> napi::Result<u64> {
|
||||
pub(crate) fn parse_u64(value: BigInt, name: &str) -> napi::Result<u64> {
|
||||
let (negative, value, lossless) = value.get_u64();
|
||||
if negative {
|
||||
return Err(napi::Error::from_reason(format!(
|
||||
|
||||
+19
-1
@@ -19,7 +19,10 @@ use napi::bindgen_prelude::*;
|
||||
use napi::threadsafe_function::{ThreadsafeFunction, ThreadsafeFunctionCallMode};
|
||||
use napi_derive::napi;
|
||||
|
||||
use crate::blob::{BlobFile, BlobRangeRequest, copy_blob_buffers, parse_row_ids, spawn_abortable};
|
||||
use crate::blob::{
|
||||
BlobDescriptorInput, BlobFile, BlobRangeRequest, copy_blob_buffers, parse_row_ids,
|
||||
spawn_abortable,
|
||||
};
|
||||
use crate::error::{NapiErrorExt, convert_error};
|
||||
use crate::index::Index;
|
||||
use crate::iterator::RecordBatchIterator;
|
||||
@@ -626,6 +629,21 @@ impl Table {
|
||||
})
|
||||
}
|
||||
|
||||
#[napi(catch_unwind)]
|
||||
pub fn open_blob_file<'env>(
|
||||
&self,
|
||||
env: &'env Env,
|
||||
descriptor: BlobDescriptorInput,
|
||||
signal: Option<AbortSignal>,
|
||||
) -> napi::Result<PromiseRaw<'env, BlobFile>> {
|
||||
let descriptor = descriptor.into_descriptor()?;
|
||||
let table = self.inner_ref()?.clone();
|
||||
spawn_abortable(env, signal, async move {
|
||||
let file = table.open_blob_file(&descriptor).await.default_error()?;
|
||||
Ok(BlobFile::new(file))
|
||||
})
|
||||
}
|
||||
|
||||
#[napi(catch_unwind)]
|
||||
pub fn vector_search(&self, vector: Float32Array) -> napi::Result<VectorQuery> {
|
||||
self.query()?.nearest_to(vector)
|
||||
|
||||
Reference in New Issue
Block a user