Skip to main content

lance_nd/
store.rs

1//! Storage options for tables on object stores, such as S3.
2//!
3//! The options are the Lance storage options, for example `aws_region`,
4//! `aws_endpoint` or `allow_http`. An empty map uses the defaults of the
5//! environment. Each object store needs its cargo feature: `aws`, `gcp` or
6//! `azure`.
7
8use std::collections::HashMap;
9use std::sync::Arc;
10
11use lance::Dataset;
12use lance::dataset::builder::DatasetBuilder;
13use lance::io::{ObjectStoreParams, StorageOptionsAccessor};
14
15/// Lance storage options, by key, for tables on object stores.
16///
17/// The keys are the Lance storage options, for example `aws_region`,
18/// `aws_endpoint` or `allow_http`. An empty map uses the defaults of the
19/// environment. Each object store needs its cargo feature: `aws`, `gcp` or
20/// `azure`.
21pub type StorageOptions = HashMap<String, String>;
22
23/// The object store parameters for `options`, or `None` for the defaults.
24pub(crate) fn store_params(options: &StorageOptions) -> Option<ObjectStoreParams> {
25    if options.is_empty() {
26        return None;
27    }
28    Some(ObjectStoreParams {
29        storage_options_accessor: Some(Arc::new(StorageOptionsAccessor::with_static_options(
30            options.clone(),
31        ))),
32        ..Default::default()
33    })
34}
35
36/// Open the Lance dataset at `uri` with `options`.
37pub(crate) async fn open_dataset(uri: &str, options: &StorageOptions) -> lance::Result<Dataset> {
38    DatasetBuilder::from_uri(uri)
39        .with_storage_options(options.clone())
40        .load()
41        .await
42}