From c6bf6a25d6f41784c182fddf48f2470cfadbbbdb Mon Sep 17 00:00:00 2001 From: LuQQiu Date: Tue, 3 Dec 2024 16:51:18 -0800 Subject: [PATCH] feat: add remote db uri path with folder prefix (#1901) Add remote database folder prefix support db://bucket/path/to/folder/ --- rust/lancedb/src/remote/client.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/rust/lancedb/src/remote/client.rs b/rust/lancedb/src/remote/client.rs index c560332b..93fe6b6a 100644 --- a/rust/lancedb/src/remote/client.rs +++ b/rust/lancedb/src/remote/client.rs @@ -228,6 +228,14 @@ impl RestfulLanceDbClient { }); } let db_name = parsed_url.host_str().unwrap(); + let db_prefix = { + let prefix = parsed_url.path().trim_start_matches('/'); + if prefix.is_empty() { + None + } else { + Some(prefix) + } + }; // Get the timeouts let connect_timeout = Self::get_timeout( @@ -258,6 +266,7 @@ impl RestfulLanceDbClient { db_name, host_override.is_some(), options, + db_prefix, )?) .user_agent(client_config.user_agent) .build() @@ -292,6 +301,7 @@ impl RestfulLanceDbClient { db_name: &str, has_host_override: bool, options: &RemoteOptions, + db_prefix: Option<&str>, ) -> Result { let mut headers = HeaderMap::new(); headers.insert( @@ -317,6 +327,17 @@ impl RestfulLanceDbClient { })?, ); } + if db_prefix.is_some() { + headers.insert( + "x-lancedb-database-prefix", + HeaderValue::from_str(db_prefix.unwrap()).map_err(|_| Error::InvalidInput { + message: format!( + "non-ascii database prefix '{}' provided", + db_prefix.unwrap() + ), + })?, + ); + } if let Some(v) = options.0.get("account_name") { headers.insert(