Skip to content

Commit

Permalink
feat: don't require empty config for cloud scan_parquet (#11819)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Oct 18, 2023
1 parent d6ef2e4 commit c3e1c1e
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions crates/polars-io/src/cloud/object_store_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ fn err_missing_feature(feature: &str, scheme: &str) -> BuildResult {
"feature '{}' must be enabled in order to use '{}' cloud urls", feature, scheme,
);
}
#[cfg(any(feature = "azure", feature = "aws", feature = "gcp"))]
fn err_missing_configuration(feature: &str, scheme: &str) -> BuildResult {
polars_bail!(
ComputeError:
"configuration '{}' must be provided in order to use '{}' cloud urls", feature, scheme,
);
}

/// Build an [`ObjectStore`] based on the URL and passed in url. Return the cloud location and an implementation of the object store.
pub async fn build_object_store(url: &str, options: Option<&CloudOptions>) -> BuildResult {
Expand All @@ -47,6 +40,11 @@ pub async fn build_object_store(url: &str, options: Option<&CloudOptions>) -> Bu
}

let cloud_type = CloudType::from_str(url)?;
let options = key
.1
.as_ref()
.map(Cow::Borrowed)
.unwrap_or_else(|| Cow::Owned(Default::default()));
let store = match cloud_type {
CloudType::File => {
let local = LocalFileSystem::new();
Expand All @@ -55,11 +53,6 @@ pub async fn build_object_store(url: &str, options: Option<&CloudOptions>) -> Bu
CloudType::Aws => {
#[cfg(feature = "aws")]
{
let options = key
.1
.as_ref()
.map(Cow::Borrowed)
.unwrap_or_else(|| Cow::Owned(Default::default()));
let store = options.build_aws(url).await?;
Ok::<_, PolarsError>(Arc::new(store) as Arc<dyn ObjectStore>)
}
Expand All @@ -68,25 +61,19 @@ pub async fn build_object_store(url: &str, options: Option<&CloudOptions>) -> Bu
},
CloudType::Gcp => {
#[cfg(feature = "gcp")]
match key.1.as_ref() {
Some(options) => {
let store = options.build_gcp(url)?;
Ok::<_, PolarsError>(Arc::new(store) as Arc<dyn ObjectStore>)
},
_ => return err_missing_configuration("gcp", &cloud_location.scheme),
{
let store = options.build_gcp(url)?;
Ok::<_, PolarsError>(Arc::new(store) as Arc<dyn ObjectStore>)
}
#[cfg(not(feature = "gcp"))]
return err_missing_feature("gcp", &cloud_location.scheme);
},
CloudType::Azure => {
{
#[cfg(feature = "azure")]
match key.1.as_ref() {
Some(options) => {
let store = options.build_azure(url)?;
Ok::<_, PolarsError>(Arc::new(store) as Arc<dyn ObjectStore>)
},
_ => return err_missing_configuration("azure", &cloud_location.scheme),
{
let store = options.build_azure(url)?;
Ok::<_, PolarsError>(Arc::new(store) as Arc<dyn ObjectStore>)
}
}
#[cfg(not(feature = "azure"))]
Expand Down

0 comments on commit c3e1c1e

Please sign in to comment.