tustvold commented on code in PR #3540: URL: https://github.com/apache/arrow-datafusion/pull/3540#discussion_r977462564
########## datafusion-cli/src/object_storage.rs: ########## @@ -0,0 +1,124 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::{env, str::FromStr, sync::Arc}; + +use datafusion::datasource::object_store::ObjectStoreProvider; +use object_store::{aws::AmazonS3Builder, gcp::GoogleCloudStorageBuilder}; +use url::Url; + +#[derive(Debug, PartialEq, Eq, clap::ArgEnum, Clone)] +pub enum ObjectStoreRegistrationOptions { Review Comment: ```suggestion pub enum ObjectStoreScheme { ``` ########## datafusion-cli/src/object_storage.rs: ########## @@ -0,0 +1,124 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::{env, str::FromStr, sync::Arc}; + +use datafusion::datasource::object_store::ObjectStoreProvider; +use object_store::{aws::AmazonS3Builder, gcp::GoogleCloudStorageBuilder}; +use url::Url; + +#[derive(Debug, PartialEq, Eq, clap::ArgEnum, Clone)] +pub enum ObjectStoreRegistrationOptions { + S3, + GCS, + Unsupported, Review Comment: I would be tempted to drop this, and return an error in `FromStr` instead ########## datafusion-cli/src/object_storage.rs: ########## @@ -0,0 +1,80 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::{env, str::FromStr, sync::Arc}; + +use datafusion::datasource::object_store::ObjectStoreProvider; +use object_store::{aws::AmazonS3Builder, gcp::GoogleCloudStorageBuilder}; +use url::Url; + +#[derive(Debug, PartialEq, Eq, clap::ArgEnum, Clone)] +pub enum ObjectStoreRegistrationOptions { + S3, + GCS, + Unsupported, +} + +impl FromStr for ObjectStoreRegistrationOptions { + type Err = String; + + fn from_str(input: &str) -> Result<Self, Self::Err> { + // clap::ArgEnum::from_str(input, true) + match input { + "s3" => Ok(ObjectStoreRegistrationOptions::S3), + "gcs" => Ok(ObjectStoreRegistrationOptions::GCS), + _ => Ok(ObjectStoreRegistrationOptions::Unsupported), + } + } +} + +#[derive(Debug)] +pub struct DatafusionCliObjectStoreProvider {} + +/// ObjectStoreProvider for S3 and GCS +impl ObjectStoreProvider for DatafusionCliObjectStoreProvider { + fn get_by_url(&self, url: &Url) -> Option<Arc<dyn object_store::ObjectStore>> { + if let (Ok(object_store_option), Some(host)) = ( + ObjectStoreRegistrationOptions::from_str(url.scheme()), + url.host_str(), + ) { + match object_store_option { + ObjectStoreRegistrationOptions::S3 => { + match AmazonS3Builder::from_env().with_bucket_name(host).build() { + Ok(s3) => Some(Arc::new(s3)), + Err(_) => None, + } Review Comment: You could write ``` Some(AmazonS3Builder::from_env() .with_bucket_name(host).build() .map(Arc::new).ok()?) ``` But it is a bit derived, and I think what you have written is better. The problem is that whilst `Arc<AmazonS3>` can be coerced to `Arc<dyn ObjectStore>`, `Option<Arc<AmazonS3>>` can't be coerced to `Option<Arc<dyn ObjectStore>>` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
