feat(sdk): support bound parameters in data prewarm (#5076)

Data prewarm methods accept filter expressions but cannot bind their
values, which forces applications to build literal SQL themselves. This
adds optional positional and named parameters to data-prewarm submission
and typed previews across Rust, Python, and TypeScript. Values use the
existing typed Arrow SQL transport and remain separate from the filter
text. Existing calls and job-handle behavior are preserved;
parameterized filters require a compatible LanceDB Enterprise server.

This was accomplished with the following changes:

- Add `PrewarmDataOptions::parameters(RecordBatch)` and forward the
batch through SQL submission and `EXPLAIN PREWARM` requests.
- Reuse Python's `QueryParameters` conversion for
synchronous/asynchronous, legacy/job-returning, and typed preview
methods.
- Add TypeScript positional-array, named-object, and explicit Arrow
parameter inputs, with safe scalar encoding and native IPC forwarding.
- Keep parameter values out of Rust option debug output and reject
invalid input before submission where possible.
- Add transport and codec regression tests, including injection-shaped
strings, typed Arrow values, legacy method forwarding, and typed preview
bindings.
- Document bound filters in the cache-prewarm guide with Python,
TypeScript, and Rust examples; update generic SQL parameter
documentation.

### Usage and behaviour

```python
job = table.prewarm_data_async(
    ["payload"], filter="id >= $minimum", parameters={"minimum": 1000}
)
job.wait()
```

```typescript
const job = await table.prewarmDataAsync({
  columns: ["payload"], filter: "id >= $1", parameters: [1000],
});
await job.wait();
```

Python accepts a sequence, mapping, or one-row Arrow batch/table.
TypeScript accepts scalar arrays/objects or one-row Arrow input; safe
integers and bigint use Int64, fractional numbers use Float64. Rust
accepts a one-row Arrow batch. Parameters bind filter values, while
table identity, branch, and concurrency keep their existing interfaces.
Submission-only methods also forward bindings and retain their existing
return behavior. Typed preview helpers accept the same parameters
without creating a job.

### Testing

Python prewarm Flight transport tests pass (65 cases), Embedded
compatibility tests pass (6 cases), and focused Node parameter/prewarm
tests pass (45 cases, including ten codec and native-boundary cases).
Earlier matching-server verification passed 57 Python/SQL scenarios, 14
Node scenarios, and Rust SDK checks, covering selective and empty plans,
typed values, authorization, pinned branches, legacy methods, and
injection-shaped strings. A bound job also survives a full runtime
restart. The guide submission examples were also verified in Python,
TypeScript, and Rust; the TypeScript example type-checks. Live-server
checks used filesystem storage.
This commit is contained in:
Bruno Ramirez
2026-11-18 11:07:32 -08:00
committed by GitHub
parent 3907a492c0
commit 23f9d5a741
22 changed files with 613 additions and 50 deletions
+16
View File
@@ -33,6 +33,7 @@ pub struct PrewarmDataOptions {
pub columns: Option<Vec<String>>,
pub filter: Option<String>,
pub concurrency: Option<f64>,
pub parameters: Option<Buffer>,
}
impl PrewarmDataOptions {
@@ -40,6 +41,21 @@ impl PrewarmDataOptions {
let mut options =
lancedb::table::PrewarmDataOptions::new().columns(self.columns.unwrap_or_default());
options.filter = self.filter;
if let Some(parameters) = self.parameters {
let mut batches = ipc_file_to_batches(parameters.to_vec())
.and_then(|reader| {
reader
.collect::<std::result::Result<Vec<_>, _>>()
.map_err(Into::into)
})
.map_err(|error| napi::Error::from_reason(error.to_string()))?;
if batches.len() != 1 || batches[0].num_rows() != 1 {
return Err(napi::Error::from_reason(
"prewarm parameters must contain one row in one batch",
));
}
options.parameters = Some(batches.remove(0));
}
if let Some(value) = self.concurrency {
if !value.is_finite() || value.fract() != 0.0 || value < 1.0 || value > u32::MAX as f64
{