mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 20:44:00 +00:00
feat(rust): align prewarm options and test job submission contracts
This commit is contained in:
@@ -304,6 +304,22 @@ branch. The server never needs to scan rows merely to evaluate the predicate.
|
||||
`prewarmData({ columns, filter, parameters, concurrency })` accept the same
|
||||
options as the job-returning methods but return after acceptance without retaining the handle.
|
||||
The existing TypeScript `prewarmData(columns)` array form remains supported.
|
||||
Rust `prewarm_data()` also accepts the same `PrewarmDataOptions` as durable
|
||||
submission and Explain, including filters and concurrency:
|
||||
|
||||
```rust
|
||||
use lancedb::table::PrewarmDataOptions;
|
||||
|
||||
table.prewarm_data(PrewarmDataOptions::new()
|
||||
.columns(["video"])
|
||||
.filter("quality > 0.7")
|
||||
.concurrency(4)).await?;
|
||||
```
|
||||
|
||||
Existing Rust `prewarm_data(None)` and `prewarm_data(Some(columns))` calls remain
|
||||
supported. The convenience method returns after acceptance and discards the job
|
||||
handle; it does not poll for warming completion.
|
||||
|
||||
These methods require SQL PREWARM support and Flight SQL connectivity.
|
||||
Unsupported servers fail without a REST fallback or silently
|
||||
dropping options. Repeated submissions may create distinct jobs; warming
|
||||
|
||||
@@ -4490,6 +4490,15 @@ async fn remote_optimize_branch_options_are_not_dropped() {
|
||||
shutdown.send(()).unwrap();
|
||||
}
|
||||
|
||||
/// Exercise the public facade without permitting unrelated database requests.
|
||||
fn public_remote_table(inner: impl crate::table::BaseTable + 'static) -> crate::Table {
|
||||
let database =
|
||||
RemoteDatabase::new_mock(|request: reqwest::Request| -> http::Response<String> {
|
||||
panic!("unexpected database request: {}", request.url());
|
||||
});
|
||||
crate::Table::new(Arc::new(inner), Arc::new(database))
|
||||
}
|
||||
|
||||
fn prewarm_result() -> RecordBatch {
|
||||
RecordBatch::try_from_iter([
|
||||
(
|
||||
@@ -4586,7 +4595,7 @@ async fn remote_prewarm_data_returns_the_durable_job_without_polling() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_legacy_prewarm_data_submits_sql_and_returns_on_acceptance() {
|
||||
async fn remote_public_prewarm_preserves_column_selectors() {
|
||||
for columns in [None, Some(vec![]), Some(vec!["payload".into()])] {
|
||||
let service = TestSqlService {
|
||||
adaptive: true,
|
||||
@@ -4609,7 +4618,12 @@ async fn remote_legacy_prewarm_data_submits_sql_and_returns_on_acceptance() {
|
||||
Default::default(),
|
||||
Some(sql),
|
||||
);
|
||||
table.prewarm_data(columns.clone()).await.unwrap();
|
||||
let table = public_remote_table(table);
|
||||
if columns.is_none() {
|
||||
table.prewarm_data(None).await.unwrap();
|
||||
} else {
|
||||
table.prewarm_data(columns.clone()).await.unwrap();
|
||||
}
|
||||
let projection = if columns.as_ref().is_some_and(|c| !c.is_empty()) {
|
||||
"\"payload\""
|
||||
} else {
|
||||
@@ -4956,3 +4970,267 @@ async fn remote_prewarm_preview_uses_sql_without_any_http_jobs() {
|
||||
shutdown.send(()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_public_prewarm_accepts_shared_options_without_polling() {
|
||||
use crate::table::PrewarmDataOptions;
|
||||
for (options, tail) in [
|
||||
(
|
||||
PrewarmDataOptions::new()
|
||||
.columns(["payload"])
|
||||
.filter("id >= 10")
|
||||
.concurrency(4),
|
||||
", concurrency = 4) AS SELECT \"payload\" FROM \"clips\" WHERE id >= 10",
|
||||
),
|
||||
(
|
||||
PrewarmDataOptions::new().filter("id >= 10"),
|
||||
") AS SELECT * FROM \"clips\" WHERE id >= 10",
|
||||
),
|
||||
(
|
||||
PrewarmDataOptions::new()
|
||||
.columns(["payload"])
|
||||
.concurrency(2),
|
||||
", concurrency = 2) AS SELECT \"payload\" FROM \"clips\"",
|
||||
),
|
||||
] {
|
||||
let service = TestSqlService {
|
||||
adaptive: true,
|
||||
result: prewarm_result(),
|
||||
..Default::default()
|
||||
};
|
||||
let statements = service.statements.clone();
|
||||
let headers = service.headers.clone();
|
||||
let (sql, shutdown) = start_sql_service(service, ClientConfig::default()).await;
|
||||
let remote = RemoteTable::new_with_sql_client(
|
||||
client_with_handler(|request| -> http::Response<String> {
|
||||
panic!("convenience prewarm must not use HTTP: {}", request.url());
|
||||
}),
|
||||
"analytics".into(),
|
||||
"clips".into(),
|
||||
vec!["team".into(), "inner".into()],
|
||||
"team$inner$clips".into(),
|
||||
Default::default(),
|
||||
Some(sql),
|
||||
)
|
||||
.with_branch(Some("o'brien".into()));
|
||||
let table = public_remote_table(remote);
|
||||
table.prewarm_data(options).await.unwrap();
|
||||
assert_eq!(
|
||||
*statements.lock().unwrap(),
|
||||
[format!("PREWARM WITH (branch = 'o''brien'{tail}")]
|
||||
);
|
||||
let headers = headers.lock().unwrap();
|
||||
assert!(!headers.is_empty());
|
||||
assert!(
|
||||
headers
|
||||
.iter()
|
||||
.all(|h| h.database == "analytics" && h.namespace_path == "team$inner")
|
||||
);
|
||||
shutdown.send(()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_public_prewarm_rejects_invalid_options_before_submission() {
|
||||
use crate::table::PrewarmDataOptions;
|
||||
let service = TestSqlService {
|
||||
adaptive: true,
|
||||
result: prewarm_result(),
|
||||
..Default::default()
|
||||
};
|
||||
let statements = service.statements.clone();
|
||||
let (sql, shutdown) = start_sql_service(service, ClientConfig::default()).await;
|
||||
let table = public_remote_table(RemoteTable::new_with_sql_client(
|
||||
client_with_handler(|request| -> http::Response<String> {
|
||||
panic!("invalid prewarm must not use HTTP: {}", request.url());
|
||||
}),
|
||||
"analytics".into(),
|
||||
"clips".into(),
|
||||
vec![],
|
||||
"clips".into(),
|
||||
Default::default(),
|
||||
Some(sql),
|
||||
));
|
||||
for options in [
|
||||
PrewarmDataOptions::new().concurrency(0),
|
||||
PrewarmDataOptions::new().filter(" "),
|
||||
PrewarmDataOptions::new().filter("id > 0; DROP TABLE clips"),
|
||||
] {
|
||||
assert!(matches!(
|
||||
table.prewarm_data(options).await.unwrap_err(),
|
||||
Error::InvalidInput { .. }
|
||||
));
|
||||
}
|
||||
assert!(statements.lock().unwrap().is_empty());
|
||||
shutdown.send(()).unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_public_optimize_options_preserve_submission_contract() {
|
||||
use crate::table::{OptimizeOptions, OptimizeOverrides};
|
||||
enum Input {
|
||||
Options(OptimizeOptions),
|
||||
Overrides(OptimizeOverrides),
|
||||
}
|
||||
let default_target = OptimizeOptions::default().target_rows_per_fragment;
|
||||
let tuned_suffix = ", target_rows_per_fragment = 100, max_source_rows = 500, \
|
||||
io_buffer_size = 0, batch_size = 16";
|
||||
for (input, suffix) in [
|
||||
(Input::Options(OptimizeOptions::default()), String::new()),
|
||||
(
|
||||
Input::Overrides(OptimizeOverrides::default()),
|
||||
String::new(),
|
||||
),
|
||||
(
|
||||
Input::Options(OptimizeOptions {
|
||||
target_rows_per_fragment: 100,
|
||||
max_source_rows: Some(500),
|
||||
io_buffer_size: Some(0),
|
||||
batch_size: Some(16),
|
||||
..Default::default()
|
||||
}),
|
||||
tuned_suffix.into(),
|
||||
),
|
||||
(
|
||||
Input::Overrides(OptimizeOverrides {
|
||||
target_rows_per_fragment: Some(100),
|
||||
max_source_rows: Some(500),
|
||||
io_buffer_size: Some(0),
|
||||
batch_size: Some(16),
|
||||
}),
|
||||
tuned_suffix.into(),
|
||||
),
|
||||
(
|
||||
Input::Overrides(OptimizeOverrides {
|
||||
target_rows_per_fragment: Some(default_target),
|
||||
io_buffer_size: Some(0),
|
||||
..Default::default()
|
||||
}),
|
||||
format!(", target_rows_per_fragment = {default_target}, io_buffer_size = 0"),
|
||||
),
|
||||
] {
|
||||
let service = TestSqlService {
|
||||
adaptive: true,
|
||||
result: RecordBatch::try_from_iter([(
|
||||
"job_id",
|
||||
Arc::new(StringArray::from(vec!["public-compaction-job"])) as ArrayRef,
|
||||
)])
|
||||
.unwrap(),
|
||||
..Default::default()
|
||||
};
|
||||
let statements = service.statements.clone();
|
||||
let headers = service.headers.clone();
|
||||
let (sql, shutdown) = start_sql_service(service, ClientConfig::default()).await;
|
||||
let polls = Arc::new(AtomicUsize::new(0));
|
||||
let observed = polls.clone();
|
||||
let client = client_with_handler(move |request| {
|
||||
assert_eq!(request.url().path(), "/v1/jobs/describe");
|
||||
let body: serde_json::Value =
|
||||
serde_json::from_slice(request.body().unwrap().as_bytes().unwrap()).unwrap();
|
||||
assert_eq!(body["job_id"], "public-compaction-job");
|
||||
observed.fetch_add(1, Ordering::SeqCst);
|
||||
http::Response::builder()
|
||||
.status(200)
|
||||
.body(serde_json::json!({
|
||||
"job_id": "public-compaction-job", "job_type": "compact", "job_state": "DONE",
|
||||
"result": {
|
||||
"partial_commit": false, "rows_succeeded": 12, "rows_failed": 0,
|
||||
"completion_percentage": 100.0, "files_added": 1, "files_removed": 3,
|
||||
"fragments_added": 1, "fragments_removed": 3
|
||||
}
|
||||
}).to_string())
|
||||
.unwrap()
|
||||
});
|
||||
let remote = RemoteTable::new_with_sql_client(
|
||||
client,
|
||||
"analytics".into(),
|
||||
"events".into(),
|
||||
vec!["team".into(), "reports".into()],
|
||||
"team$reports$events".into(),
|
||||
Default::default(),
|
||||
Some(sql),
|
||||
)
|
||||
.with_branch(Some("o'brien".into()));
|
||||
let table = public_remote_table(remote);
|
||||
let job = match input {
|
||||
Input::Options(options) => table.optimize_async(options).await.unwrap(),
|
||||
Input::Overrides(options) => table.optimize_async(options).await.unwrap(),
|
||||
};
|
||||
assert_eq!(job.id(), Some("public-compaction-job"));
|
||||
assert_eq!(polls.load(Ordering::SeqCst), 0);
|
||||
let expected =
|
||||
format!("OPTIMIZE \"events\" REWRITE DATA WITH (branch = 'o''brien'{suffix})");
|
||||
assert_eq!(*statements.lock().unwrap(), [expected.clone()]);
|
||||
let result = job.wait().await.unwrap();
|
||||
assert_eq!(result.rows_succeeded, 12);
|
||||
assert_eq!(result.fragments_removed, Some(3));
|
||||
assert!(polls.load(Ordering::SeqCst) > 0);
|
||||
assert_eq!(*statements.lock().unwrap(), [expected]);
|
||||
let headers = headers.lock().unwrap();
|
||||
assert!(!headers.is_empty());
|
||||
assert!(
|
||||
headers
|
||||
.iter()
|
||||
.all(|h| h.database == "analytics" && h.namespace_path == "team$reports")
|
||||
);
|
||||
shutdown.send(()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_public_optimize_rejects_unsupported_requests_before_submission() {
|
||||
use crate::table::{IndexOptimizeOptions, OptimizeAction, OptimizeOptions, OptimizeOverrides};
|
||||
let service = TestSqlService {
|
||||
adaptive: true,
|
||||
..Default::default()
|
||||
};
|
||||
let statements = service.statements.clone();
|
||||
let (sql, shutdown) = start_sql_service(service, ClientConfig::default()).await;
|
||||
let table = public_remote_table(RemoteTable::new_with_sql_client(
|
||||
client_with_handler(|request| -> http::Response<String> {
|
||||
panic!("invalid optimize must not use HTTP: {}", request.url());
|
||||
}),
|
||||
"analytics".into(),
|
||||
"events".into(),
|
||||
vec![],
|
||||
"events".into(),
|
||||
Default::default(),
|
||||
Some(sql),
|
||||
));
|
||||
for action in [
|
||||
OptimizeAction::All,
|
||||
OptimizeAction::Prune {
|
||||
older_than: Some(chrono::Duration::days(1)),
|
||||
delete_unverified: None,
|
||||
error_if_tagged_old_versions: None,
|
||||
},
|
||||
OptimizeAction::Index(IndexOptimizeOptions::default()),
|
||||
] {
|
||||
assert!(matches!(
|
||||
table.optimize_async(action).await.unwrap_err(),
|
||||
Error::NotSupported { .. }
|
||||
));
|
||||
}
|
||||
assert!(matches!(
|
||||
table
|
||||
.optimize_async(OptimizeOptions {
|
||||
max_source_bytes: Some(1024),
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
.unwrap_err(),
|
||||
Error::NotSupported { .. }
|
||||
));
|
||||
assert!(matches!(
|
||||
table
|
||||
.optimize_async(OptimizeOverrides {
|
||||
max_source_rows: Some(0),
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
.unwrap_err(),
|
||||
Error::InvalidInput { .. }
|
||||
));
|
||||
assert!(statements.lock().unwrap().is_empty());
|
||||
shutdown.send(()).unwrap();
|
||||
}
|
||||
|
||||
@@ -3158,9 +3158,35 @@ impl Table {
|
||||
/// or binary data may not be practical to prewarm. This feature is intended
|
||||
/// for workloads that issue many queries against the same columns.
|
||||
///
|
||||
/// If `columns` is `None`, all columns are prewarmed.
|
||||
pub async fn prewarm_data(&self, columns: Option<Vec<String>>) -> Result<()> {
|
||||
self.inner.prewarm_data(columns).await
|
||||
/// Accepts the same [`PrewarmDataOptions`] as [`Self::prewarm_data_async`]
|
||||
/// and [`Self::explain_prewarm_data`], including filters and per-executor
|
||||
/// concurrency. Existing `None` and `Some(Vec<String>)` column selectors
|
||||
/// remain supported. Omitted or empty columns select all fields.
|
||||
///
|
||||
/// ```no_run
|
||||
/// # async fn warm(table: &lancedb::Table) -> lancedb::Result<()> {
|
||||
/// use lancedb::table::PrewarmDataOptions;
|
||||
/// table.prewarm_data(PrewarmDataOptions::new()
|
||||
/// .columns(["video"])
|
||||
/// .filter("quality > 0.7")
|
||||
/// .concurrency(4)).await?;
|
||||
/// // Existing column-only calls retain their behaviour.
|
||||
/// table.prewarm_data(Some(vec!["video".to_owned()])).await?;
|
||||
/// table.prewarm_data(None).await?;
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
pub async fn prewarm_data(&self, options: impl Into<PrewarmDataOptions>) -> Result<()> {
|
||||
let options = options.into();
|
||||
if options.filter.is_none() && options.concurrency.is_none() {
|
||||
// Keep the established column-only hook for custom table implementations.
|
||||
let columns = (!options.columns.is_empty()).then_some(options.columns);
|
||||
self.inner.prewarm_data(columns).await
|
||||
} else {
|
||||
// Confirm submission, then discard the durable handle without polling.
|
||||
self.inner.prewarm_data_async(options).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Submit a durable data-cache prewarm job through SQL and return when accepted.
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
|
||||
//! Options, previews, and results for data-cache prewarm.
|
||||
|
||||
/// Data prewarm settings for [`super::Table::prewarm_data_async`] and
|
||||
/// [`super::Table::explain_prewarm_data`].
|
||||
/// Shared settings for data prewarm submission and preview methods on [`super::Table`].
|
||||
///
|
||||
/// The table handle supplies the database, namespace, and branch. Omitted
|
||||
/// columns warm all fields. The filter selects conservative metadata ranges;
|
||||
@@ -37,6 +36,12 @@ impl std::fmt::Debug for PrewarmDataOptions {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Option<Vec<String>>> for PrewarmDataOptions {
|
||||
fn from(columns: Option<Vec<String>>) -> Self {
|
||||
Self::new().columns(columns.unwrap_or_default())
|
||||
}
|
||||
}
|
||||
|
||||
impl PrewarmDataOptions {
|
||||
/// Use server defaults and warm every column.
|
||||
pub fn new() -> Self {
|
||||
|
||||
Reference in New Issue
Block a user