From 33a13f0738aaa75de2256b2bc75515ad4e5cfa6b Mon Sep 17 00:00:00 2001 From: Will Jones Date: Wed, 4 Mar 2026 15:27:32 -0800 Subject: [PATCH] fixes for breaking changes --- python/src/storage_options.rs | 39 +++++-------- rust/lancedb/src/database/namespace.rs | 78 ++++++-------------------- 2 files changed, 29 insertions(+), 88 deletions(-) diff --git a/python/src/storage_options.rs b/python/src/storage_options.rs index d00c2aa16..29ad9cebf 100644 --- a/python/src/storage_options.rs +++ b/python/src/storage_options.rs @@ -66,13 +66,10 @@ impl StorageOptionsProvider for PyStorageOptionsProviderWrapper { .inner .bind(py) .call_method0("fetch_storage_options") - .map_err(|e| lance_core::Error::IO { - source: Box::new(std::io::Error::other(format!( - "Failed to call fetch_storage_options: {}", - e - ))), - location: snafu::location!(), - })?; + .map_err(|e| lance_core::Error::io_source(Box::new(std::io::Error::other(format!( + "Failed to call fetch_storage_options: {}", + e + )))))?; // If result is None, return None if result.is_none() { @@ -81,26 +78,19 @@ impl StorageOptionsProvider for PyStorageOptionsProviderWrapper { // Extract the result dict - should be a flat Map let result_dict = result.downcast::().map_err(|_| { - lance_core::Error::InvalidInput { - source: "fetch_storage_options() must return None or a dict of string key-value pairs".into(), - location: snafu::location!(), - } + lance_core::Error::invalid_input( + "fetch_storage_options() must return a dict of string key-value pairs or None", + ) })?; // Convert all entries to HashMap let mut storage_options = HashMap::new(); for (key, value) in result_dict.iter() { let key_str: String = key.extract().map_err(|e| { - lance_core::Error::InvalidInput { - source: format!("Storage option key must be a string: {}", e).into(), - location: snafu::location!(), - } + lance_core::Error::invalid_input(format!("Storage option key must be a string: {}", e)) })?; let value_str: String = value.extract().map_err(|e| { - lance_core::Error::InvalidInput { - source: format!("Storage option value must be a string: {}", e).into(), - location: snafu::location!(), - } + lance_core::Error::invalid_input(format!("Storage option value must be a string: {}", e)) })?; storage_options.insert(key_str, value_str); } @@ -109,13 +99,10 @@ impl StorageOptionsProvider for PyStorageOptionsProviderWrapper { }) }) .await - .map_err(|e| lance_core::Error::IO { - source: Box::new(std::io::Error::other(format!( - "Task join error: {}", - e - ))), - location: snafu::location!(), - })? + .map_err(|e| lance_core::Error::io_source(Box::new(std::io::Error::other(format!( + "Task join error: {}", + e + )))))? } fn provider_id(&self) -> String { diff --git a/rust/lancedb/src/database/namespace.rs b/rust/lancedb/src/database/namespace.rs index 90b5c19bd..61db3002f 100644 --- a/rust/lancedb/src/database/namespace.rs +++ b/rust/lancedb/src/database/namespace.rs @@ -11,14 +11,13 @@ use lance_io::object_store::{ObjectStoreParams, StorageOptionsAccessor}; use lance_namespace::{ LanceNamespace, models::{ - CreateEmptyTableRequest, CreateNamespaceRequest, CreateNamespaceResponse, - DeclareTableRequest, DescribeNamespaceRequest, DescribeNamespaceResponse, - DescribeTableRequest, DropNamespaceRequest, DropNamespaceResponse, DropTableRequest, - ListNamespacesRequest, ListNamespacesResponse, ListTablesRequest, ListTablesResponse, + CreateNamespaceRequest, CreateNamespaceResponse, DeclareTableRequest, + DescribeNamespaceRequest, DescribeNamespaceResponse, DescribeTableRequest, + DropNamespaceRequest, DropNamespaceResponse, DropTableRequest, ListNamespacesRequest, + ListNamespacesResponse, ListTablesRequest, ListTablesResponse, }, }; use lance_namespace_impls::ConnectBuilder; -use log::warn; use crate::database::ReadConsistency; use crate::error::{Error, Result}; @@ -213,63 +212,18 @@ impl Database for LanceNamespaceDatabase { ..Default::default() }; - let (location, initial_storage_options) = - match self.namespace.declare_table(declare_request).await { - Ok(response) => { - let loc = response.location.ok_or_else(|| Error::Runtime { - message: "Table location is missing from declare_table response" - .to_string(), - })?; - // Use storage options from response, fall back to self.storage_options - let opts = response - .storage_options - .or_else(|| Some(self.storage_options.clone())) - .filter(|o| !o.is_empty()); - (loc, opts) - } - Err(e) => { - // Check if the error is "not supported" and try create_empty_table as fallback - let err_str = e.to_string().to_lowercase(); - if err_str.contains("not supported") || err_str.contains("not implemented") { - warn!( - "declare_table is not supported by the namespace client, \ - falling back to deprecated create_empty_table. \ - create_empty_table is deprecated and will be removed in Lance 3.0.0. \ - Please upgrade your namespace client to support declare_table." - ); - #[allow(deprecated)] - let create_empty_request = CreateEmptyTableRequest { - id: Some(table_id.clone()), - ..Default::default() - }; - - #[allow(deprecated)] - let create_response = self - .namespace - .create_empty_table(create_empty_request) - .await - .map_err(|e| Error::Runtime { - message: format!("Failed to create empty table: {}", e), - })?; - - let loc = create_response.location.ok_or_else(|| Error::Runtime { - message: "Table location is missing from create_empty_table response" - .to_string(), - })?; - // For deprecated path, use self.storage_options - let opts = if self.storage_options.is_empty() { - None - } else { - Some(self.storage_options.clone()) - }; - (loc, opts) - } else { - return Err(Error::Runtime { - message: format!("Failed to declare table: {}", e), - }); - } - } - }; + let (location, initial_storage_options) = { + let response = self.namespace.declare_table(declare_request).await?; + let loc = response.location.ok_or_else(|| Error::Runtime { + message: "Table location is missing from declare_table response".to_string(), + })?; + // Use storage options from response, fall back to self.storage_options + let opts = response + .storage_options + .or_else(|| Some(self.storage_options.clone())) + .filter(|o| !o.is_empty()); + (loc, opts) + }; let write_params = if let Some(storage_opts) = initial_storage_options { let mut params = request.write_options.lance_write_params.unwrap_or_default();