You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "roeap (via GitHub)" <gi...@apache.org> on 2023/04/17 09:41:04 UTC

[GitHub] [arrow-rs] roeap commented on a diff in pull request #4077: (object_store): Instantiate object store from provided url

roeap commented on code in PR #4077:
URL: https://github.com/apache/arrow-rs/pull/4077#discussion_r1168434636


##########
object_store/src/options.rs:
##########
@@ -0,0 +1,166 @@
+// 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::collections::HashMap;
+pub use std::str::FromStr;
+
+#[cfg(any(feature = "gcp", feature = "aws", feature = "azure", feature = "http"))]
+use crate::client::ClientOptions;
+
+#[cfg(any(feature = "aws"))]
+use crate::aws::AmazonS3ConfigKey;
+#[cfg(feature = "azure")]
+use crate::azure::AzureConfigKey;
+#[cfg(feature = "gcp")]
+use crate::gcp::GoogleConfigKey;
+
+/// Options used for configuring backend store
+#[derive(Clone, Debug, Default)]
+pub struct StoreOptions {
+    /// Store specific options like key, secret, region etc.
+    _store_options: HashMap<String, String>,
+
+    /// Options specific for the internal client
+    #[cfg(any(feature = "gcp", feature = "aws", feature = "azure", feature = "http"))]
+    client_options: ClientOptions,
+}
+
+impl StoreOptions {
+    /// Create a new instance of [`StorageOptions`]
+    #[cfg(any(feature = "gcp", feature = "aws", feature = "azure", feature = "http"))]
+    pub fn new(
+        store_options: HashMap<String, String>,
+        client_options: ClientOptions,

Review Comment:
   Not feeling too strongly about this, but the `from_iterator` method also will accept a HashMap as it should fit the type constraints as well. So maybe it makes sense to have the generic type in `new` and drop the `from_iterator` method?



##########
object_store/src/options.rs:
##########
@@ -0,0 +1,166 @@
+// 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::collections::HashMap;
+pub use std::str::FromStr;
+
+#[cfg(any(feature = "gcp", feature = "aws", feature = "azure", feature = "http"))]
+use crate::client::ClientOptions;
+
+#[cfg(any(feature = "aws"))]
+use crate::aws::AmazonS3ConfigKey;
+#[cfg(feature = "azure")]
+use crate::azure::AzureConfigKey;
+#[cfg(feature = "gcp")]
+use crate::gcp::GoogleConfigKey;
+
+/// Options used for configuring backend store
+#[derive(Clone, Debug, Default)]
+pub struct StoreOptions {
+    /// Store specific options like key, secret, region etc.
+    _store_options: HashMap<String, String>,
+
+    /// Options specific for the internal client
+    #[cfg(any(feature = "gcp", feature = "aws", feature = "azure", feature = "http"))]
+    client_options: ClientOptions,
+}
+
+impl StoreOptions {
+    /// Create a new instance of [`StorageOptions`]
+    #[cfg(any(feature = "gcp", feature = "aws", feature = "azure", feature = "http"))]
+    pub fn new(
+        store_options: HashMap<String, String>,
+        client_options: ClientOptions,
+    ) -> Self {
+        Self {
+            _store_options: store_options,
+            client_options,
+        }
+    }
+
+    #[cfg(not(any(
+        feature = "gcp",
+        feature = "aws",
+        feature = "azure",
+        feature = "http"
+    )))]
+    pub fn new(store_options: HashMap<String, String>) -> Self {
+        Self {
+            _store_options: store_options,
+        }
+    }
+
+    #[cfg(any(feature = "gcp", feature = "aws", feature = "azure", feature = "http"))]
+    pub fn from_iterable<I: IntoIterator<Item = (impl AsRef<str>, impl Into<String>)>>(
+        iter: I,
+        client_options: ClientOptions,
+    ) -> Self {
+        let store_options: HashMap<String, String> = iter
+            .into_iter()
+            .map(|(key, value)| (key.as_ref().to_ascii_lowercase(), value.into()))
+            .collect();
+
+        Self {
+            _store_options: store_options,
+            client_options,
+        }
+    }
+
+    #[cfg(not(any(
+        feature = "gcp",
+        feature = "aws",
+        feature = "azure",
+        feature = "http"
+    )))]
+    pub fn from_iterable<I: IntoIterator<Item = (impl AsRef<str>, impl Into<String>)>>(
+        iter: I,
+    ) -> Self {
+        let store_options: HashMap<String, String> = iter
+            .into_iter()
+            .map(|(key, value)| (key.as_ref().to_ascii_lowercase(), value.into()))
+            .collect();
+
+        Self {
+            _store_options: store_options,
+        }
+    }
+
+    /// Gets an instance of ClientOptions
+    #[cfg(any(feature = "gcp", feature = "aws", feature = "azure", feature = "http"))]
+    pub fn get_client_options(&self) -> ClientOptions {
+        self.client_options.clone()
+    }
+
+    /// Ensures that provided options are compatible with Azure
+    #[cfg(feature = "azure")]
+    pub fn get_azure_options(&self) -> HashMap<AzureConfigKey, String> {
+        self._store_options
+            .iter()
+            .map(|(key, value)| {
+                let conf_key =
+                    AzureConfigKey::from_str(&key.to_ascii_lowercase()).unwrap();

Review Comment:
   should we either return an error or omit the keys that will panic here?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org