diff --git a/docs/src/js/classes/Table.md b/docs/src/js/classes/Table.md index 2ff43a226..a1fd9da86 100644 --- a/docs/src/js/classes/Table.md +++ b/docs/src/js/classes/Table.md @@ -1105,7 +1105,7 @@ retrying with the settings removed. optimizeAsync(_options?): Promise> ``` -Submit remote compaction and return its durable job after acceptance. +Submit remote Optimize and return its durable job after acceptance. Uses SQL OPTIMIZE, inheriting branch and namespace from this table. Requires a compatible remote server and table Ownership plus parent Usage. Local and diff --git a/docs/web/maintenance/compaction.mdx b/docs/web/maintenance/compaction.mdx index 0fdc64d0d..58135629f 100644 --- a/docs/web/maintenance/compaction.mdx +++ b/docs/web/maintenance/compaction.mdx @@ -531,8 +531,7 @@ under `stats.compaction`. The old names are removed without aliases. ### Optimize naming migration -The SDK uses Optimize names for submission and durable results, and Optimize -Data names for the settings specific to data rewrites: +The SDK uses Optimize names for submission, settings, and durable results: | Previous name | Current name | | --- | --- | @@ -551,7 +550,9 @@ removed `compactionOptions` and `dataOptions` properties before submission. Python rejects the old wrapper keywords. This prevents a requested work limit from being silently ignored. `CompactionStats` and `OptimizeStats.compaction` still identify the compaction -phase within Embedded's broader maintenance cycle. The server job type `compact`, +phase within Embedded's broader maintenance cycle. The algorithm-specific +`compaction_mode` field remains in Python and Rust's underlying Lance options. +The server job type `compact`, table tuning key `job_types.compaction`, and realtime SSTable maintenance methods are unchanged. @@ -583,3 +584,9 @@ submission. Rust accepts `OptimizeOptions` directly for both submission methods, Its separate index-maintenance options are `IndexOptimizeOptions`. `OptimizeOverrides` retains omitted-versus-explicit values when inheriting remote policy. No `data_options` or `dataOptions` wrapper is accepted. + +Enterprise convenience and durable Optimize use the same SQL submission and +job-receipt validation. A successful receipt contains exactly one nonempty +`job_id`. A malformed receipt raises without resubmitting; inspect existing jobs +before retrying because the server may already have accepted the work. +Convenience calls discard the validated handle without polling for completion. diff --git a/nodejs/lancedb/table.ts b/nodejs/lancedb/table.ts index 8ff3ba265..c432529e2 100644 --- a/nodejs/lancedb/table.ts +++ b/nodejs/lancedb/table.ts @@ -1310,7 +1310,7 @@ export abstract class Table { */ abstract restore(): Promise; /** - * Submit remote compaction and return its durable job after acceptance. + * Submit remote Optimize and return its durable job after acceptance. * * Uses SQL OPTIMIZE, inheriting branch and namespace from this table. Requires * a compatible remote server and table Ownership plus parent Usage. Local and @@ -1328,7 +1328,7 @@ export abstract class Table { async optimizeAsync( _options?: OptimizeOptions, ): Promise> { - throw new Error("compaction jobs are only supported on remote tables"); + throw new Error("Optimize jobs are only supported on remote tables"); } /** diff --git a/python/python/lancedb/table.py b/python/python/lancedb/table.py index 4cdd769d7..4343ae04c 100644 --- a/python/python/lancedb/table.py +++ b/python/python/lancedb/table.py @@ -3163,7 +3163,7 @@ class Table(ABC): """ def optimize_async(self, **options: Unpack[OptimizeOptions]) -> Job[OptimizeResult]: - """Submit remote compaction and return a durable job after acceptance. + """Submit remote Optimize and return a durable job after acceptance. Uses SQL OPTIMIZE with the table handle's branch and namespace. Supports the four per-job settings in @@ -3185,7 +3185,7 @@ class Table(ABC): >>> result = job.wait() # doctest: +SKIP >>> print(result.rows_succeeded) # doctest: +SKIP """ - raise NotImplementedError("compaction jobs are only supported on remote tables") + raise NotImplementedError("Optimize jobs are only supported on remote tables") @abstractmethod def optimize(self, **options: Unpack[OptimizeOptions]) -> OptimizeStats: @@ -9579,7 +9579,7 @@ class AsyncTable: async def optimize_async( self, **options: Unpack[OptimizeOptions] ) -> AsyncJob[OptimizeResult]: - """Submit remote compaction; await the returned job for actual results. + """Submit remote Optimize; await the returned job for actual results. See [Table.optimize_async][lancedb.table.Table.optimize_async] for options, permissions, completion semantics and compatibility requirements. diff --git a/python/python/tests/test_remote_db.py b/python/python/tests/test_remote_db.py index 42eaecdfd..09d0ba71a 100644 --- a/python/python/tests/test_remote_db.py +++ b/python/python/tests/test_remote_db.py @@ -7543,6 +7543,7 @@ def test_remote_function_registration_transports_max_concurrency(): @pytest.mark.asyncio +@pytest.mark.parametrize("method", ["optimize", "optimize_async"]) @pytest.mark.parametrize("asynchronous", [False, True]) @pytest.mark.parametrize( "options,sql_options", @@ -7573,7 +7574,7 @@ def test_remote_function_registration_transports_max_concurrency(): ], ) async def test_remote_optimize_forwards_per_job_data_options( - asynchronous, options, sql_options + asynchronous, method, options, sql_options ): flight = pytest.importorskip("pyarrow.flight") @@ -7584,25 +7585,26 @@ async def test_remote_optimize_forwards_per_job_data_options( def do_get(self, context, ticket): self.tickets.append(ticket.ticket) - return flight.RecordBatchStream( - pa.table({"ok": pa.array([], type=pa.bool_())}) - ) + return flight.RecordBatchStream(pa.table({"job_id": ["optimize-job"]})) server = AckServer() with _mock_remote_sql_connection(server) as kwargs: if asynchronous: db = await lancedb.connect_async(**kwargs) table = await db.create_table("test", [{"id": 1}]) - stats = await table.optimize(**options) + stats = await getattr(table, method)(**options) else: table = lancedb.connect(**kwargs).create_table("test", [{"id": 1}]) - stats = table.optimize(**options) + stats = getattr(table, method)(**options) assert len(server.tickets) == 1 assert b"OPTIMIZE" in server.tickets[0] assert all(option in server.tickets[0] for option in sql_options) if not sql_options: assert b"WITH (" not in server.tickets[0] - assert stats.prune.bytes_removed == 0 + if method == "optimize": + assert stats.prune.bytes_removed == 0 + else: + assert stats.id == "optimize-job" def test_remote_optimize_does_not_drop_options_after_server_rejection(): @@ -7646,9 +7648,7 @@ def test_remote_optimize_skips_prune_and_index(): def do_get(self, context, ticket): self.tickets.append(ticket.ticket) - return flight.RecordBatchStream( - pa.table({"ok": pa.array([], type=pa.bool_())}) - ) + return flight.RecordBatchStream(pa.table({"job_id": ["optimize-job"]})) server = AckServer() with _mock_remote_table_with_sql(server) as table: @@ -8523,8 +8523,13 @@ async def test_remote_compaction_job_result_and_reopen(asynchronous, outcome): assert b"target_rows_per_fragment = 100" in server.tickets[0] +@pytest.mark.asyncio +@pytest.mark.parametrize("asynchronous", [False, True]) +@pytest.mark.parametrize("method", ["optimize", "optimize_async"]) @pytest.mark.parametrize("ids", [[], [None], [""], ["a", "b"]]) -def test_remote_compaction_rejects_ambiguous_receipt_without_resubmission(ids): +async def test_remote_optimize_rejects_ambiguous_receipt_without_resubmission( + asynchronous, method, ids +): flight = pytest.importorskip("pyarrow.flight") class Server(flight.FlightServerBase): @@ -8540,10 +8545,16 @@ def test_remote_compaction_rejects_ambiguous_receipt_without_resubmission(ids): server = Server() with _mock_remote_sql_connection(server) as kwargs: - db = lancedb.connect(**kwargs) - table = db.create_table("test", [{"id": 1}]) - with pytest.raises(Exception, match="inspect jobs before retrying"): - table.optimize_async() + if asynchronous: + db = await lancedb.connect_async(**kwargs) + table = await db.create_table("test", [{"id": 1}]) + with pytest.raises(Exception, match="inspect jobs before retrying"): + await getattr(table, method)() + else: + db = lancedb.connect(**kwargs) + table = db.create_table("test", [{"id": 1}]) + with pytest.raises(Exception, match="inspect jobs before retrying"): + getattr(table, method)() assert server.calls == 1 diff --git a/python/src/table.rs b/python/src/table.rs index abdc425da..4a4d1c49a 100644 --- a/python/src/table.rs +++ b/python/src/table.rs @@ -31,7 +31,7 @@ use lancedb::index::scalar::FtsIndexBuilder; use lancedb::table::{ AddDataMode, ColumnAlteration, Duration, FieldMetadataUpdate, FtsToken as LanceDbFtsToken, FunctionRefreshPlanningConfig, FunctionRefreshPodResources, FunctionWorkerResourceBudget, - IndexRemapMode, NewColumnTransform, OptimizeDataMode, OptimizeOptions, Ref, + IndexRemapMode, NewColumnTransform, OptimizeDataMode, OptimizeOptions, OptimizeOverrides, Ref, RefreshColumnOptions, Table as LanceDbTable, }; use lancedb::tokenize as lancedb_tokenize; @@ -487,10 +487,27 @@ fn optional_i64_bounded_u64(value: &Bound<'_, PyAny>, name: &str) -> PyResult>) -> PyResult { +/// Preserve Python field presence while sharing Embedded and Enterprise parsing. +#[derive(Default)] +struct ParsedOptimizeOptions { + options: OptimizeOptions, + target_specified: bool, +} + +impl ParsedOptimizeOptions { + fn into_remote_overrides(self) -> PyResult { + let mut overrides = OptimizeOverrides::try_from(self.options).infer_error()?; + if !self.target_specified { + overrides.target_rows_per_fragment = None; + } + Ok(overrides) + } +} + +fn parse_optimize_options(options: Option<&Bound<'_, PyDict>>) -> PyResult { let mut parsed = OptimizeOptions::default(); let Some(options) = options else { - return Ok(parsed); + return Ok(ParsedOptimizeOptions::default()); }; for (key, value) in options.iter() { @@ -551,13 +568,16 @@ fn parse_data_options(options: Option<&Bound<'_, PyDict>>) -> PyResult { return Err(PyValueError::new_err(format!( - "Invalid compaction option: {key}" + "Invalid Optimize option: {key}" ))); } } } - Ok(parsed) + Ok(ParsedOptimizeOptions { + options: parsed, + target_specified: options.contains("target_rows_per_fragment")?, + }) } /// Statistics about a compaction operation. @@ -2295,23 +2315,14 @@ impl Table { }) } - /// Submit remote compaction and retain its durable job and actual result. + /// Submit remote Optimize and retain its durable job and actual result. #[pyo3(signature = (data_options=None))] pub fn optimize_async<'py>( self_: PyRef<'py, Self>, data_options: Option<&Bound<'py, PyDict>>, ) -> PyResult> { let inner = self_.inner_ref()?.clone(); - let target_specified = data_options - .map(|options| options.contains("target_rows_per_fragment")) - .transpose()? - .unwrap_or(false); - let options = parse_data_options(data_options)?; - let mut overrides = - lancedb::table::optimize::OptimizeOverrides::try_from(options).infer_error()?; - if !target_specified { - overrides.target_rows_per_fragment = None; - } + let overrides = parse_optimize_options(data_options)?.into_remote_overrides()?; future_into_py(self_.py(), async move { let job = inner.optimize_async(overrides).await.infer_error()?; Ok(crate::job::Job::new_typed(job)) @@ -2342,11 +2353,7 @@ impl Table { )); } let inner = self_.inner_ref()?.clone(); - let target_specified = data_options - .map(|options| options.contains("target_rows_per_fragment")) - .transpose()? - .unwrap_or(false); - let data_options = parse_data_options(data_options)?; + let data_options = parse_optimize_options(data_options)?; let older_than = if let Some(ms) = cleanup_since_ms { if ms > i64::MAX as u64 { return Err(PyValueError::new_err(format!( @@ -2364,22 +2371,17 @@ impl Table { if rewrite_only { inner .optimize(lancedb::table::OptimizeAction::RewriteDataWithOptions { - options: data_options, + options: data_options.options, remap_options: None, }) .await } else { inner - .optimize_full(data_options, older_than, None, delete_unverified) + .optimize_full(data_options.options, older_than, None, delete_unverified) .await } } else { - let mut overrides = - lancedb::table::optimize::OptimizeOverrides::try_from(data_options) - .infer_error()?; - if !target_specified { - overrides.target_rows_per_fragment = None; - } + let overrides = data_options.into_remote_overrides()?; if rewrite_only { inner.optimize(overrides).await } else { diff --git a/rust/lancedb/src/remote/sql_test.rs b/rust/lancedb/src/remote/sql_test.rs index 3803a61eb..cf97f57c9 100644 --- a/rust/lancedb/src/remote/sql_test.rs +++ b/rust/lancedb/src/remote/sql_test.rs @@ -2693,6 +2693,7 @@ async fn remote_drop_materialized_view_uses_a_query_job() { async fn remote_optimize_submits_a_compaction_job_over_sql() { let service = TestSqlService { adaptive: true, + result: optimize_result(), ..Default::default() }; let statements = service.statements.clone(); @@ -2721,8 +2722,8 @@ async fn remote_optimize_submits_a_compaction_job_over_sql() { .await .unwrap(); - // The SQL job adapter does not expose compaction metrics, so - // `compaction` is a zeroed placeholder, not real numbers -- but it must + // Convenience submission discards the job handle and returns placeholder + // statistics rather than waiting for committed metrics. `compaction` must // be `Some`: callers (including the Python/Node bindings) unwrap it // unconditionally on success. assert_eq!( @@ -2748,6 +2749,7 @@ async fn remote_optimize_submits_a_compaction_job_over_sql() { async fn remote_optimize_on_a_branch_submits_a_with_clause_over_sql() { let service = TestSqlService { adaptive: true, + result: optimize_result(), ..Default::default() }; let statements = service.statements.clone(); @@ -2788,13 +2790,14 @@ async fn remote_optimize_on_a_branch_submits_a_with_clause_over_sql() { /// action because `Prune` and `Index` are not supported remotely -- so a /// retry on that failure resubmitted another compaction job. `optimize_full` /// is what both the Python and Node bindings now call instead of -/// orchestrating `Compact`, `Prune`, and `Index` themselves; on a remote +/// orchestrating data rewrites, `Prune`, and `Index` themselves; on a remote /// table it must submit only the compaction job and return zeroed prune /// stats rather than attempting `Prune` and `Index` at all. #[tokio::test] async fn remote_optimize_full_skips_prune_and_index() { let service = TestSqlService { adaptive: true, + result: optimize_result(), ..Default::default() }; let statements = service.statements.clone(); @@ -2855,6 +2858,7 @@ async fn remote_optimize_full_skips_prune_and_index() { async fn remote_optimize_full_treats_delete_unverified_false_as_default() { let service = TestSqlService { adaptive: true, + result: optimize_result(), ..Default::default() }; let statements = service.statements.clone(); @@ -2911,6 +2915,7 @@ async fn remote_optimize_full_rejects_explicit_pruning_options() { ) { let service = TestSqlService { adaptive: true, + result: optimize_result(), ..Default::default() }; let statements = service.statements.clone(); @@ -4264,6 +4269,7 @@ async fn remote_optimize_forwards_per_job_options_on_main_and_branch() { for branch in [None, Some("o'brien")] { let service = TestSqlService { adaptive: true, + result: optimize_result(), ..Default::default() }; let statements = service.statements.clone(); @@ -4320,7 +4326,7 @@ async fn remote_optimize_forwards_per_job_options_on_main_and_branch() { } #[tokio::test] -async fn remote_compact_preserves_omissions_and_explicit_default_values() { +async fn remote_optimize_preserves_omissions_and_explicit_default_values() { use crate::table::{OptimizeOptions, OptimizeOverrides}; let target = OptimizeOptions::default().target_rows_per_fragment; for (options, suffix) in [ @@ -4342,6 +4348,7 @@ async fn remote_compact_preserves_omissions_and_explicit_default_values() { ] { let service = TestSqlService { adaptive: true, + result: optimize_result(), ..Default::default() }; let statements = service.statements.clone(); @@ -4499,6 +4506,14 @@ fn public_remote_table(inner: impl crate::table::BaseTable + 'static) -> crate:: crate::Table::new(Arc::new(inner), Arc::new(database)) } +fn optimize_result() -> RecordBatch { + RecordBatch::try_from_iter([( + "job_id", + Arc::new(StringArray::from(vec!["optimize-job"])) as ArrayRef, + )]) + .unwrap() +} + fn prewarm_result() -> RecordBatch { RecordBatch::try_from_iter([ ( @@ -5234,3 +5249,92 @@ async fn remote_public_optimize_rejects_unsupported_requests_before_submission() assert!(statements.lock().unwrap().is_empty()); shutdown.send(()).unwrap(); } + +#[tokio::test] +async fn remote_optimize_convenience_and_durable_validate_the_same_receipt() { + use crate::table::OptimizeOverrides; + for result in [ + RecordBatch::try_from_iter([( + "other", + Arc::new(StringArray::from(vec!["id"])) as ArrayRef, + )]) + .unwrap(), + RecordBatch::try_from_iter([( + "job_id", + Arc::new(StringArray::from(Vec::>::new())) as ArrayRef, + )]) + .unwrap(), + RecordBatch::try_from_iter([( + "job_id", + Arc::new(StringArray::from(vec![None::<&str>])) as ArrayRef, + )]) + .unwrap(), + RecordBatch::try_from_iter([("job_id", Arc::new(StringArray::from(vec![""])) as ArrayRef)]) + .unwrap(), + RecordBatch::try_from_iter([( + "job_id", + Arc::new(StringArray::from(vec!["one", "two"])) as ArrayRef, + )]) + .unwrap(), + optimize_result(), + ] { + let valid = result == optimize_result(); + for (adaptive, defer) in [(false, false), (true, false), (true, true)] { + for durable in [false, true] { + let service = TestSqlService { + adaptive, + defer, + result: result.clone(), + ..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 { + panic!( + "Optimize submission must not poll or use REST: {}", + request.url() + ); + }), + "analytics".into(), + "events".into(), + vec![], + "events".into(), + Default::default(), + Some(sql), + )); + let submitted = if durable { + table + .optimize_async(OptimizeOverrides::default()) + .await + .map(|job| { + assert_eq!(job.id(), Some("optimize-job")); + }) + } else { + table + .optimize(OptimizeOverrides::default()) + .await + .map(|stats| { + assert_eq!( + stats.compaction, + Some(lance::dataset::optimize::CompactionMetrics::default()) + ); + assert!(stats.prune.is_none()); + }) + }; + if valid { + submitted.unwrap(); + } else { + let error = submitted.unwrap_err(); + assert!(matches!(error, Error::Runtime { .. }), "{error}"); + assert!(error.to_string().contains("inspect jobs before retrying")); + } + assert_eq!( + *statements.lock().unwrap(), + ["OPTIMIZE \"events\" REWRITE DATA"] + ); + shutdown.send(()).unwrap(); + } + } + } +} diff --git a/rust/lancedb/src/remote/table.rs b/rust/lancedb/src/remote/table.rs index b1ce8b52c..9e0ca34b8 100644 --- a/rust/lancedb/src/remote/table.rs +++ b/rust/lancedb/src/remote/table.rs @@ -4040,48 +4040,12 @@ impl BaseTable for RemoteTable { Ok(()) } - /// `OptimizeAction::RewriteData`, or `OptimizeAction::RewriteDataWithOptions` with no custom - /// `remap_options` is supported remotely: it submits a durable - /// compaction job through the server's `OPTIMIZE ... REWRITE DATA` - /// SQL statement, the same atomic, single-worker, index-safe path the - /// server uses for its own automatic compaction. `.wait()` below waits - /// for that SQL statement's own execution to finish, which only confirms - /// the compaction job was accepted into the server's job registry; the - /// compaction job itself then runs asynchronously on the server, so this - /// call can return well before the table is actually compacted. - /// `OptimizeStats::compaction` is `Some(CompactionMetrics::default())`, - /// a placeholder rather than `None` -- callers (including the - /// Python/Node bindings) unwrap it unconditionally on success -- because - /// the SQL job adapter does not expose per-job compaction metrics. - /// `OptimizeAction::All`, `::Prune`, and `::Index` remain unsupported - /// remotely: there is no SQL statement yet for version pruning or index - /// optimization. A branch-scoped table handle submits a - /// `WITH (branch = '')` clause; the server resolves and validates - /// the selected target. Per-job - /// `target_rows_per_fragment`, `max_source_rows`, `io_buffer_size`, and - /// `batch_size` are forwarded in the SQL `WITH` clause. Other non-default - /// options are rejected before submission. Servers must support these - /// SQL options. Parser errors and unknown optimize option errors become - /// `NotSupported` with the server diagnostic after one SQL submission. - /// No settings are removed and the operation is never resubmitted. + /// Submit through the same SQL receipt-validation path as `optimize_async`, + /// then discard the durable handle without polling for rewrite completion. + /// Convenience callers retain the existing placeholder statistics; actual + /// committed results are available by waiting on the job-returning method. async fn optimize(&self, action: OptimizeAction) -> Result { - self.check_mutable().await?; - let overrides = action.into_remote_overrides()?; - let statement = optimize::statement(&self.name, self.branch.as_deref(), &overrides)?; - let sql_client = self.sql_client.clone().ok_or_else(|| Error::NotSupported { - message: "SQL is unavailable for this remote table client".to_string(), - })?; - // `OptimizeStats` carries `lance::dataset::optimize` metric types that - // are not `Serialize`/`Deserialize`/`Clone`, which `Job` requires, - // so the job itself only signals completion; the real (placeholder) - // value is built afterward. - sql_client - .submit_as_job(statement, self.namespace.clone(), || async { Ok(()) }) - .await - .map_err(optimize::map_optimize_error)? - .wait() - .await - .map_err(optimize::map_optimize_error)?; + self.optimize_async(action.into_remote_overrides()?).await?; Ok(OptimizeStats { compaction: Some(lance::dataset::optimize::CompactionMetrics::default()), prune: None, @@ -4097,7 +4061,7 @@ impl BaseTable for RemoteTable { .sql_client .as_ref() .ok_or_else(|| Error::NotSupported { - message: "compaction jobs require a Flight SQL endpoint".into(), + message: "Optimize jobs require a Flight SQL endpoint".into(), })?; let query = client .execute(crate::database::ExecuteQueryRequest { diff --git a/rust/lancedb/src/remote/table/optimize.rs b/rust/lancedb/src/remote/table/optimize.rs index 097932f57..e53ab51b8 100644 --- a/rust/lancedb/src/remote/table/optimize.rs +++ b/rust/lancedb/src/remote/table/optimize.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: Copyright The LanceDB Authors -//! Compaction options supported by the remote SQL submission protocol. +//! Optimize options supported by the remote SQL submission protocol. use crate::error::{Error, Result}; pub(super) fn statement( @@ -9,7 +9,7 @@ pub(super) fn statement( branch: Option<&str>, options: &crate::table::optimize::OptimizeOverrides, ) -> Result { - let mut settings = compaction_sql_options(options)?; + let mut settings = rewrite_sql_options(options)?; if let Some(branch) = branch { settings.insert(0, format!("branch = {}", super::quote_sql_string(branch))); } @@ -28,7 +28,7 @@ pub(super) fn statement( pub(super) fn receipt(batches: &[arrow_array::RecordBatch]) -> Result { use arrow_array::{Array, StringArray}; let invalid = || { - Error::Runtime { message: "OPTIMIZE did not return a single nonempty job_id receipt; inspect jobs before retrying because compaction may already have been submitted".into() } + Error::Runtime { message: "OPTIMIZE did not return a single nonempty job_id receipt; inspect jobs before retrying because Optimize may already have been submitted".into() } }; if batches.iter().map(|batch| batch.num_rows()).sum::() != 1 { return Err(invalid()); @@ -47,7 +47,7 @@ pub(super) fn receipt(batches: &[arrow_array::RecordBatch]) -> Result { Ok(ids.value(0).into()) } -pub(super) fn compaction_sql_options( +pub(super) fn rewrite_sql_options( options: &crate::table::optimize::OptimizeOverrides, ) -> Result> { for (name, value) in [ @@ -78,8 +78,8 @@ pub(super) fn compaction_sql_options( Ok(result) } -const UNSUPPORTED_OPTIMIZE: &str = "Compaction on an Enterprise table requires support for OPTIMIZE REWRITE DATA. Upgrade LanceDB Enterprise to a compatible release."; -const UNSUPPORTED_OPTIONS: &str = "The requested compaction options are not supported by this version of LanceDB Enterprise. Upgrade to a compatible release; requested options will not be removed or retried."; +const UNSUPPORTED_OPTIMIZE: &str = "Optimize on an Enterprise table requires support for OPTIMIZE
REWRITE DATA. Upgrade LanceDB Enterprise to a compatible release."; +const UNSUPPORTED_OPTIONS: &str = "The requested Optimize options are not supported by this version of LanceDB Enterprise. Upgrade to a compatible release; requested options will not be removed or retried."; /// The client generates the whole statement, so parser errors indicate a /// client/server syntax mismatch. Match option errors without enumerating names. @@ -248,13 +248,13 @@ mod tests { #[test] fn omissions_and_explicit_default_target_are_distinct() { assert!( - compaction_sql_options(&OptimizeOverrides::default()) + rewrite_sql_options(&OptimizeOverrides::default()) .unwrap() .is_empty() ); let target = OptimizeOptions::default().target_rows_per_fragment; assert_eq!( - compaction_sql_options(&OptimizeOverrides { + rewrite_sql_options(&OptimizeOverrides { target_rows_per_fragment: Some(target), io_buffer_size: Some(0), ..Default::default() @@ -295,7 +295,7 @@ mod tests { }, ] { assert!(matches!( - compaction_sql_options(&options), + rewrite_sql_options(&options), Err(Error::InvalidInput { .. }) )); } @@ -309,7 +309,7 @@ mod receipt_tests { use std::sync::Arc; #[test] - fn compaction_receipt_requires_one_unambiguous_registry_id() { + fn optimize_receipt_requires_one_unambiguous_registry_id() { let batch = |ids: Vec>| { RecordBatch::try_from_iter([("job_id", Arc::new(StringArray::from(ids)) as ArrayRef)]) .unwrap() diff --git a/rust/lancedb/src/table.rs b/rust/lancedb/src/table.rs index 3d6de9ce5..a7339976a 100644 --- a/rust/lancedb/src/table.rs +++ b/rust/lancedb/src/table.rs @@ -901,13 +901,13 @@ pub trait BaseTable: std::fmt::Display + std::fmt::Debug + Send + Sync { async fn tags(&self) -> Result>; /// Optimize the dataset. async fn optimize(&self, action: OptimizeAction) -> Result; - /// Submit remote compaction and retain its durable job and actual outcome. + /// Submit remote Optimize and retain its durable job and actual outcome. async fn optimize_async( &self, _options: optimize::OptimizeOverrides, ) -> Result> { Err(Error::NotSupported { - message: "compaction jobs are only supported on remote tables".into(), + message: "Optimize jobs are only supported on remote tables".into(), }) } /// Add columns to the table. @@ -2082,7 +2082,7 @@ impl Table { self.inner.optimize(action.into()).await } - /// Submit remote compaction and return its durable job after acceptance. + /// Submit remote Optimize and return its durable job after acceptance. /// /// Uses SQL `OPTIMIZE ... REWRITE DATA` with the table handle's namespace /// and branch. The four fields of [`optimize::OptimizeOverrides`] retain @@ -2102,7 +2102,7 @@ impl Table { /// when omitted values must be distinguished from explicit SDK defaults. /// /// ```no_run - /// # async fn compact(table: &lancedb::Table) -> lancedb::Result<()> { + /// # async fn optimize(table: &lancedb::Table) -> lancedb::Result<()> { /// let job = table.optimize_async(lancedb::table::OptimizeOptions::default()).await?; /// let result = job.wait().await?; /// println!("Committed {} rows", result.rows_succeeded); diff --git a/rust/lancedb/src/table/optimize.rs b/rust/lancedb/src/table/optimize.rs index cba78ff11..0cc10dd46 100644 --- a/rust/lancedb/src/table/optimize.rs +++ b/rust/lancedb/src/table/optimize.rs @@ -336,7 +336,7 @@ pub enum OptimizeAction { /// /// ``` /// use lancedb::{Table, table::{OptimizeOptions, OptimizeAction}}; - /// # async fn compact(table: &Table) -> lancedb::Result<()> { + /// # async fn optimize(table: &Table) -> lancedb::Result<()> { /// table.optimize(OptimizeAction::RewriteDataWithOptions { /// options: OptimizeOptions { /// target_rows_per_fragment: 100_000,