mirror of
https://github.com/lancedb/lancedb.git
synced 2026-09-12 08:12:28 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72ac16ba76 |
@@ -656,6 +656,7 @@ pub struct ConnectRequest {
|
|||||||
/// - `/path/to/database` - local database on file system.
|
/// - `/path/to/database` - local database on file system.
|
||||||
/// - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud object store
|
/// - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud object store
|
||||||
/// - `db://dbname` - LanceDB Cloud
|
/// - `db://dbname` - LanceDB Cloud
|
||||||
|
/// - `db://` with a host override - remote tables in the storage root
|
||||||
pub uri: String,
|
pub uri: String,
|
||||||
|
|
||||||
#[cfg(feature = "remote")]
|
#[cfg(feature = "remote")]
|
||||||
@@ -768,6 +769,8 @@ impl ConnectBuilder {
|
|||||||
///
|
///
|
||||||
/// This option is only used when connecting to LanceDB Cloud (db:// URIs)
|
/// This option is only used when connecting to LanceDB Cloud (db:// URIs)
|
||||||
/// and will be ignored for other URIs.
|
/// and will be ignored for other URIs.
|
||||||
|
/// Use the URI `db://` together with a host override to connect to remote
|
||||||
|
/// tables stored directly in the storage root.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
@@ -1354,6 +1357,34 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_connect_remote_storage_root() {
|
||||||
|
let conn = ConnectBuilder::new("db://")
|
||||||
|
.region("us-east-1")
|
||||||
|
.api_key("my-api-key")
|
||||||
|
.host_override("https://example.com")
|
||||||
|
.execute()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let (impl_name, properties) = conn.namespace_client_config().await.unwrap();
|
||||||
|
assert_eq!(impl_name, "rest");
|
||||||
|
assert_eq!(properties["uri"], "https://example.com");
|
||||||
|
assert_eq!(properties["header.x-lancedb-database"], "");
|
||||||
|
|
||||||
|
let result = ConnectBuilder::new("db://")
|
||||||
|
.region("us-east-1")
|
||||||
|
.api_key("my-api-key")
|
||||||
|
.execute()
|
||||||
|
.await;
|
||||||
|
assert!(matches!(
|
||||||
|
result,
|
||||||
|
Err(Error::InvalidInput { message })
|
||||||
|
if message.contains("A host override is required")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "remote")]
|
#[cfg(feature = "remote")]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_connect_rejects_header_provider_with_oauth_config() {
|
async fn test_connect_rejects_header_provider_with_oauth_config() {
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
//! - `/path/to/database` - local database on file system.
|
//! - `/path/to/database` - local database on file system.
|
||||||
//! - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud object store
|
//! - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud object store
|
||||||
//! - `db://dbname` - Lance Cloud
|
//! - `db://dbname` - Lance Cloud
|
||||||
|
//! - `db://` with a host override - remote tables in the storage root
|
||||||
//!
|
//!
|
||||||
//! You can also use [`ConnectBuilder`] to configure the connection to the database.
|
//! You can also use [`ConnectBuilder`] to configure the connection to the database.
|
||||||
//!
|
//!
|
||||||
|
|||||||
@@ -349,18 +349,22 @@ pub struct ParsedDbUrl {
|
|||||||
|
|
||||||
/// Parse a database URL and extract the database name and optional prefix.
|
/// Parse a database URL and extract the database name and optional prefix.
|
||||||
///
|
///
|
||||||
/// Expected format: `db://db_name` or `db://db_name/prefix`
|
/// Expected format: `db://db_name`, `db://db_name/prefix`, or `db://` when
|
||||||
|
/// connecting to the storage root through a host override.
|
||||||
pub fn parse_db_url(db_url: &str) -> Result<ParsedDbUrl> {
|
pub fn parse_db_url(db_url: &str) -> Result<ParsedDbUrl> {
|
||||||
let parsed_url = url::Url::parse(db_url).map_err(|err| Error::InvalidInput {
|
let parsed_url = url::Url::parse(db_url).map_err(|err| Error::InvalidInput {
|
||||||
message: format!("db_url is not a valid URL. '{db_url}'. Error: {err}"),
|
message: format!("db_url is not a valid URL. '{db_url}'. Error: {err}"),
|
||||||
})?;
|
})?;
|
||||||
debug_assert_eq!(parsed_url.scheme(), "db");
|
debug_assert_eq!(parsed_url.scheme(), "db");
|
||||||
if !parsed_url.has_host() {
|
let db_name = match parsed_url.host_str() {
|
||||||
return Err(Error::InvalidInput {
|
Some(db_name) => db_name.to_string(),
|
||||||
message: format!("Invalid database URL (missing host) '{}'", db_url),
|
None if matches!(parsed_url.path(), "" | "/") => String::new(),
|
||||||
});
|
None => {
|
||||||
}
|
return Err(Error::InvalidInput {
|
||||||
let db_name = parsed_url.host_str().unwrap().to_string();
|
message: format!("Invalid database URL (missing host) '{}'", db_url),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
let db_prefix = {
|
let db_prefix = {
|
||||||
let prefix = parsed_url.path().trim_start_matches('/');
|
let prefix = parsed_url.path().trim_start_matches('/');
|
||||||
if prefix.is_empty() {
|
if prefix.is_empty() {
|
||||||
|
|||||||
@@ -272,6 +272,13 @@ impl RemoteDatabase {
|
|||||||
read_consistency_interval: Option<std::time::Duration>,
|
read_consistency_interval: Option<std::time::Duration>,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let parsed = super::client::parse_db_url(uri)?;
|
let parsed = super::client::parse_db_url(uri)?;
|
||||||
|
if parsed.db_name.is_empty() && host_override.is_none() {
|
||||||
|
return Err(Error::InvalidInput {
|
||||||
|
message:
|
||||||
|
"A host override is required when connecting to the storage root with 'db://'"
|
||||||
|
.to_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
let header_map = RestfulLanceDbClient::<Sender>::default_headers(
|
let header_map = RestfulLanceDbClient::<Sender>::default_headers(
|
||||||
api_key,
|
api_key,
|
||||||
region,
|
region,
|
||||||
|
|||||||
Reference in New Issue
Block a user