You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "CTTY (via GitHub)" <gi...@apache.org> on 2026/03/11 21:51:00 UTC
[PR] feat(storage): implement opendal resolving storage [iceberg-rust]
CTTY opened a new pull request, #2231:
URL: https://github.com/apache/iceberg-rust/pull/2231
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
- Closes #2210
## What changes are included in this PR?
- Add OpenDalResolvingStorage
<!--
Provide a summary of the modifications in this PR. List the main changes such as new features, bug fixes, refactoring, or any other updates.
-->
## Are these changes tested?
Added a new test
<!--
Specify what test covers (unit test, integration test, etc.).
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(storage): implement opendal resolving storage [iceberg-rust]
Posted by "CTTY (via GitHub)" <gi...@apache.org>.
CTTY commented on code in PR #2231:
URL: https://github.com/apache/iceberg-rust/pull/2231#discussion_r2943996635
##########
crates/storage/opendal/src/resolving.rs:
##########
@@ -0,0 +1,266 @@
+// 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.
+
+//! Resolving storage that auto-detects the scheme from a path and delegates
+//! to the appropriate [`OpenDalStorage`] variant.
+
+use std::collections::HashMap;
+use std::sync::{Arc, RwLock};
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use iceberg::io::{
+ FileMetadata, FileRead, FileWrite, InputFile, OutputFile, Storage, StorageConfig,
+ StorageFactory,
+};
+use iceberg::{Error, ErrorKind, Result};
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+use crate::OpenDalStorage;
+#[cfg(feature = "opendal-s3")]
+use crate::s3::CustomAwsCredentialLoader;
+
+/// Extract the scheme from a path string (e.g., `"s3://bucket/key"` → `"s3"`).
+fn extract_scheme(path: &str) -> Result<String> {
+ let url = Url::parse(path).map_err(|e| {
+ Error::new(
+ ErrorKind::DataInvalid,
+ format!("Invalid path: {path}, failed to parse URL: {e}"),
+ )
+ })?;
+ Ok(url.scheme().to_string())
+}
+
+/// Build an [`OpenDalStorage`] variant for the given scheme and config properties.
+fn build_storage_for_scheme(
+ scheme: &str,
+ props: &HashMap<String, String>,
+ #[cfg(feature = "opendal-s3")] customized_credential_load: &Option<CustomAwsCredentialLoader>,
+) -> Result<OpenDalStorage> {
+ match scheme {
+ #[cfg(feature = "opendal-s3")]
+ "s3" | "s3a" | "s3n" => {
+ let config = crate::s3::s3_config_parse(props.clone())?;
+ Ok(OpenDalStorage::S3 {
+ configured_scheme: scheme.to_string(),
+ config: Arc::new(config),
+ customized_credential_load: customized_credential_load.clone(),
+ })
+ }
+ #[cfg(feature = "opendal-gcs")]
+ "gs" => {
+ let config = crate::gcs::gcs_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Gcs {
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-oss")]
+ "oss" => {
+ let config = crate::oss::oss_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Oss {
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-azdls")]
+ "abfs" | "abfss" | "wasb" | "wasbs" => {
+ let configured_scheme: crate::azdls::AzureStorageScheme = scheme.parse()?;
+ let config = crate::azdls::azdls_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Azdls {
+ configured_scheme,
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-fs")]
+ "file" => Ok(OpenDalStorage::LocalFs),
+ #[cfg(feature = "opendal-memory")]
+ "memory" => Ok(OpenDalStorage::Memory(crate::memory::memory_config_build()?)),
+ _ => Err(Error::new(
+ ErrorKind::FeatureUnsupported,
+ format!("Unsupported storage scheme: {scheme}"),
+ )),
+ }
+}
+
+/// A resolving storage factory that creates [`OpenDalResolvingStorage`] instances.
+///
+/// This factory accepts paths from any supported storage system and dynamically
+/// delegates operations to the appropriate [`OpenDalStorage`] variant based on
+/// the path scheme.
+///
+/// # Example
+///
+/// ```rust,ignore
+/// use std::sync::Arc;
+/// use iceberg::io::FileIOBuilder;
+/// use iceberg_storage_opendal::OpenDalResolvingStorageFactory;
+///
+/// let factory = OpenDalResolvingStorageFactory::new();
+/// let file_io = FileIOBuilder::new(Arc::new(factory))
+/// .with_prop("s3.region", "us-east-1")
+/// .build();
+/// ```
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct OpenDalResolvingStorageFactory {
+ /// Custom AWS credential loader for S3 storage.
+ #[cfg(feature = "opendal-s3")]
+ #[serde(skip)]
+ customized_credential_load: Option<CustomAwsCredentialLoader>,
+}
+
+impl Default for OpenDalResolvingStorageFactory {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+impl OpenDalResolvingStorageFactory {
+ /// Create a new resolving storage factory.
+ pub fn new() -> Self {
+ Self {
+ #[cfg(feature = "opendal-s3")]
+ customized_credential_load: None,
+ }
+ }
+
+ /// Set a custom AWS credential loader for S3 storage.
+ #[cfg(feature = "opendal-s3")]
+ pub fn with_s3_credential_loader(mut self, loader: CustomAwsCredentialLoader) -> Self {
+ self.customized_credential_load = Some(loader);
+ self
+ }
+}
+
+#[typetag::serde]
+impl StorageFactory for OpenDalResolvingStorageFactory {
+ fn build(&self, config: &StorageConfig) -> Result<Arc<dyn Storage>> {
+ Ok(Arc::new(OpenDalResolvingStorage {
+ props: config.props().clone(),
+ storages: RwLock::new(HashMap::new()),
+ #[cfg(feature = "opendal-s3")]
+ customized_credential_load: self.customized_credential_load.clone(),
+ }))
+ }
+}
+
+/// A resolving storage that auto-detects the scheme from a path and delegates
+/// to the appropriate [`OpenDalStorage`] variant.
+///
+/// Sub-storages are lazily created on first use for each scheme and cached
+/// for subsequent operations.
+#[derive(Debug, Serialize, Deserialize)]
+pub struct OpenDalResolvingStorage {
+ /// Configuration properties shared across all backends.
+ props: HashMap<String, String>,
+ /// Cache of scheme → storage mappings.
+ #[serde(skip, default)]
+ storages: RwLock<HashMap<String, Arc<OpenDalStorage>>>,
Review Comment:
Currently there is a `configured_scheme` for `OpenDalStorage::{S3 , Azdls}`, the path it handles should match the configured scheme, so technically it shouldn't be using the same storage instance if the schemes are different.
https://github.com/apache/iceberg-rust/blob/main/crates/storage/opendal/src/lib.rs#L110
I'm not quite sure about the reason tho, maybe it's an OpenDal limitation? I think we can improve this in a different PR if needed
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(storage): implement opendal resolving storage [iceberg-rust]
Posted by "blackmwk (via GitHub)" <gi...@apache.org>.
blackmwk commented on code in PR #2231:
URL: https://github.com/apache/iceberg-rust/pull/2231#discussion_r2937947359
##########
crates/storage/opendal/src/resolving.rs:
##########
@@ -0,0 +1,266 @@
+// 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.
+
+//! Resolving storage that auto-detects the scheme from a path and delegates
+//! to the appropriate [`OpenDalStorage`] variant.
+
+use std::collections::HashMap;
+use std::sync::{Arc, RwLock};
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use iceberg::io::{
+ FileMetadata, FileRead, FileWrite, InputFile, OutputFile, Storage, StorageConfig,
+ StorageFactory,
+};
+use iceberg::{Error, ErrorKind, Result};
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+use crate::OpenDalStorage;
+#[cfg(feature = "opendal-s3")]
+use crate::s3::CustomAwsCredentialLoader;
+
+/// Extract the scheme from a path string (e.g., `"s3://bucket/key"` → `"s3"`).
+fn extract_scheme(path: &str) -> Result<String> {
+ let url = Url::parse(path).map_err(|e| {
+ Error::new(
+ ErrorKind::DataInvalid,
+ format!("Invalid path: {path}, failed to parse URL: {e}"),
+ )
+ })?;
+ Ok(url.scheme().to_string())
+}
+
+/// Build an [`OpenDalStorage`] variant for the given scheme and config properties.
+fn build_storage_for_scheme(
+ scheme: &str,
+ props: &HashMap<String, String>,
+ #[cfg(feature = "opendal-s3")] customized_credential_load: &Option<CustomAwsCredentialLoader>,
+) -> Result<OpenDalStorage> {
+ match scheme {
+ #[cfg(feature = "opendal-s3")]
+ "s3" | "s3a" | "s3n" => {
+ let config = crate::s3::s3_config_parse(props.clone())?;
+ Ok(OpenDalStorage::S3 {
+ configured_scheme: scheme.to_string(),
+ config: Arc::new(config),
+ customized_credential_load: customized_credential_load.clone(),
+ })
+ }
+ #[cfg(feature = "opendal-gcs")]
+ "gs" => {
+ let config = crate::gcs::gcs_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Gcs {
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-oss")]
+ "oss" => {
+ let config = crate::oss::oss_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Oss {
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-azdls")]
+ "abfs" | "abfss" | "wasb" | "wasbs" => {
+ let configured_scheme: crate::azdls::AzureStorageScheme = scheme.parse()?;
+ let config = crate::azdls::azdls_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Azdls {
+ configured_scheme,
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-fs")]
+ "file" => Ok(OpenDalStorage::LocalFs),
+ #[cfg(feature = "opendal-memory")]
+ "memory" => Ok(OpenDalStorage::Memory(crate::memory::memory_config_build()?)),
+ _ => Err(Error::new(
+ ErrorKind::FeatureUnsupported,
+ format!("Unsupported storage scheme: {scheme}"),
+ )),
+ }
+}
+
+/// A resolving storage factory that creates [`OpenDalResolvingStorage`] instances.
+///
+/// This factory accepts paths from any supported storage system and dynamically
+/// delegates operations to the appropriate [`OpenDalStorage`] variant based on
+/// the path scheme.
+///
+/// # Example
+///
+/// ```rust,ignore
+/// use std::sync::Arc;
+/// use iceberg::io::FileIOBuilder;
+/// use iceberg_storage_opendal::OpenDalResolvingStorageFactory;
+///
+/// let factory = OpenDalResolvingStorageFactory::new();
+/// let file_io = FileIOBuilder::new(Arc::new(factory))
+/// .with_prop("s3.region", "us-east-1")
+/// .build();
+/// ```
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct OpenDalResolvingStorageFactory {
+ /// Custom AWS credential loader for S3 storage.
+ #[cfg(feature = "opendal-s3")]
+ #[serde(skip)]
+ customized_credential_load: Option<CustomAwsCredentialLoader>,
+}
+
+impl Default for OpenDalResolvingStorageFactory {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+impl OpenDalResolvingStorageFactory {
+ /// Create a new resolving storage factory.
+ pub fn new() -> Self {
+ Self {
+ #[cfg(feature = "opendal-s3")]
+ customized_credential_load: None,
+ }
+ }
+
+ /// Set a custom AWS credential loader for S3 storage.
+ #[cfg(feature = "opendal-s3")]
+ pub fn with_s3_credential_loader(mut self, loader: CustomAwsCredentialLoader) -> Self {
+ self.customized_credential_load = Some(loader);
+ self
+ }
+}
+
+#[typetag::serde]
+impl StorageFactory for OpenDalResolvingStorageFactory {
+ fn build(&self, config: &StorageConfig) -> Result<Arc<dyn Storage>> {
+ Ok(Arc::new(OpenDalResolvingStorage {
+ props: config.props().clone(),
+ storages: RwLock::new(HashMap::new()),
+ #[cfg(feature = "opendal-s3")]
+ customized_credential_load: self.customized_credential_load.clone(),
+ }))
+ }
+}
+
+/// A resolving storage that auto-detects the scheme from a path and delegates
+/// to the appropriate [`OpenDalStorage`] variant.
+///
+/// Sub-storages are lazily created on first use for each scheme and cached
+/// for subsequent operations.
+#[derive(Debug, Serialize, Deserialize)]
+pub struct OpenDalResolvingStorage {
+ /// Configuration properties shared across all backends.
+ props: HashMap<String, String>,
+ /// Cache of scheme → storage mappings.
+ #[serde(skip, default)]
+ storages: RwLock<HashMap<String, Arc<OpenDalStorage>>>,
Review Comment:
This should be multi map? For example, we may need to support both s3 and s3a for S3 storage.
##########
crates/storage/opendal/src/resolving.rs:
##########
@@ -0,0 +1,266 @@
+// 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.
+
+//! Resolving storage that auto-detects the scheme from a path and delegates
+//! to the appropriate [`OpenDalStorage`] variant.
+
+use std::collections::HashMap;
+use std::sync::{Arc, RwLock};
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use iceberg::io::{
+ FileMetadata, FileRead, FileWrite, InputFile, OutputFile, Storage, StorageConfig,
+ StorageFactory,
+};
+use iceberg::{Error, ErrorKind, Result};
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+use crate::OpenDalStorage;
+#[cfg(feature = "opendal-s3")]
+use crate::s3::CustomAwsCredentialLoader;
+
+/// Extract the scheme from a path string (e.g., `"s3://bucket/key"` → `"s3"`).
+fn extract_scheme(path: &str) -> Result<String> {
+ let url = Url::parse(path).map_err(|e| {
+ Error::new(
+ ErrorKind::DataInvalid,
+ format!("Invalid path: {path}, failed to parse URL: {e}"),
+ )
+ })?;
+ Ok(url.scheme().to_string())
+}
+
+/// Build an [`OpenDalStorage`] variant for the given scheme and config properties.
+fn build_storage_for_scheme(
+ scheme: &str,
+ props: &HashMap<String, String>,
+ #[cfg(feature = "opendal-s3")] customized_credential_load: &Option<CustomAwsCredentialLoader>,
+) -> Result<OpenDalStorage> {
+ match scheme {
+ #[cfg(feature = "opendal-s3")]
+ "s3" | "s3a" | "s3n" => {
Review Comment:
I think we should make this literal constants in code. One benefit of this approach is that we could generate doc for users.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(storage): implement opendal resolving storage [iceberg-rust]
Posted by "blackmwk (via GitHub)" <gi...@apache.org>.
blackmwk commented on code in PR #2231:
URL: https://github.com/apache/iceberg-rust/pull/2231#discussion_r2943884545
##########
crates/storage/opendal/src/resolving.rs:
##########
@@ -0,0 +1,266 @@
+// 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.
+
+//! Resolving storage that auto-detects the scheme from a path and delegates
+//! to the appropriate [`OpenDalStorage`] variant.
+
+use std::collections::HashMap;
+use std::sync::{Arc, RwLock};
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use iceberg::io::{
+ FileMetadata, FileRead, FileWrite, InputFile, OutputFile, Storage, StorageConfig,
+ StorageFactory,
+};
+use iceberg::{Error, ErrorKind, Result};
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+use crate::OpenDalStorage;
+#[cfg(feature = "opendal-s3")]
+use crate::s3::CustomAwsCredentialLoader;
+
+/// Extract the scheme from a path string (e.g., `"s3://bucket/key"` → `"s3"`).
+fn extract_scheme(path: &str) -> Result<String> {
+ let url = Url::parse(path).map_err(|e| {
+ Error::new(
+ ErrorKind::DataInvalid,
+ format!("Invalid path: {path}, failed to parse URL: {e}"),
+ )
+ })?;
+ Ok(url.scheme().to_string())
+}
+
+/// Build an [`OpenDalStorage`] variant for the given scheme and config properties.
+fn build_storage_for_scheme(
+ scheme: &str,
+ props: &HashMap<String, String>,
+ #[cfg(feature = "opendal-s3")] customized_credential_load: &Option<CustomAwsCredentialLoader>,
+) -> Result<OpenDalStorage> {
+ match scheme {
+ #[cfg(feature = "opendal-s3")]
+ "s3" | "s3a" | "s3n" => {
+ let config = crate::s3::s3_config_parse(props.clone())?;
+ Ok(OpenDalStorage::S3 {
+ configured_scheme: scheme.to_string(),
+ config: Arc::new(config),
+ customized_credential_load: customized_credential_load.clone(),
+ })
+ }
+ #[cfg(feature = "opendal-gcs")]
+ "gs" => {
+ let config = crate::gcs::gcs_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Gcs {
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-oss")]
+ "oss" => {
+ let config = crate::oss::oss_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Oss {
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-azdls")]
+ "abfs" | "abfss" | "wasb" | "wasbs" => {
+ let configured_scheme: crate::azdls::AzureStorageScheme = scheme.parse()?;
+ let config = crate::azdls::azdls_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Azdls {
+ configured_scheme,
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-fs")]
+ "file" => Ok(OpenDalStorage::LocalFs),
+ #[cfg(feature = "opendal-memory")]
+ "memory" => Ok(OpenDalStorage::Memory(crate::memory::memory_config_build()?)),
+ _ => Err(Error::new(
+ ErrorKind::FeatureUnsupported,
+ format!("Unsupported storage scheme: {scheme}"),
+ )),
+ }
+}
+
+/// A resolving storage factory that creates [`OpenDalResolvingStorage`] instances.
+///
+/// This factory accepts paths from any supported storage system and dynamically
+/// delegates operations to the appropriate [`OpenDalStorage`] variant based on
+/// the path scheme.
+///
+/// # Example
+///
+/// ```rust,ignore
+/// use std::sync::Arc;
+/// use iceberg::io::FileIOBuilder;
+/// use iceberg_storage_opendal::OpenDalResolvingStorageFactory;
+///
+/// let factory = OpenDalResolvingStorageFactory::new();
+/// let file_io = FileIOBuilder::new(Arc::new(factory))
+/// .with_prop("s3.region", "us-east-1")
+/// .build();
+/// ```
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct OpenDalResolvingStorageFactory {
+ /// Custom AWS credential loader for S3 storage.
+ #[cfg(feature = "opendal-s3")]
+ #[serde(skip)]
+ customized_credential_load: Option<CustomAwsCredentialLoader>,
+}
+
+impl Default for OpenDalResolvingStorageFactory {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+impl OpenDalResolvingStorageFactory {
+ /// Create a new resolving storage factory.
+ pub fn new() -> Self {
+ Self {
+ #[cfg(feature = "opendal-s3")]
+ customized_credential_load: None,
+ }
+ }
+
+ /// Set a custom AWS credential loader for S3 storage.
+ #[cfg(feature = "opendal-s3")]
+ pub fn with_s3_credential_loader(mut self, loader: CustomAwsCredentialLoader) -> Self {
+ self.customized_credential_load = Some(loader);
+ self
+ }
+}
+
+#[typetag::serde]
+impl StorageFactory for OpenDalResolvingStorageFactory {
+ fn build(&self, config: &StorageConfig) -> Result<Arc<dyn Storage>> {
+ Ok(Arc::new(OpenDalResolvingStorage {
+ props: config.props().clone(),
+ storages: RwLock::new(HashMap::new()),
+ #[cfg(feature = "opendal-s3")]
+ customized_credential_load: self.customized_credential_load.clone(),
+ }))
+ }
+}
+
+/// A resolving storage that auto-detects the scheme from a path and delegates
+/// to the appropriate [`OpenDalStorage`] variant.
+///
+/// Sub-storages are lazily created on first use for each scheme and cached
+/// for subsequent operations.
+#[derive(Debug, Serialize, Deserialize)]
+pub struct OpenDalResolvingStorage {
+ /// Configuration properties shared across all backends.
+ props: HashMap<String, String>,
+ /// Cache of scheme → storage mappings.
+ #[serde(skip, default)]
+ storages: RwLock<HashMap<String, Arc<OpenDalStorage>>>,
Review Comment:
I was thinking we should map them into same storage? A storage instance has a lot of resources inside, like connection pool, etc.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(storage): implement opendal resolving storage [iceberg-rust]
Posted by "blackmwk (via GitHub)" <gi...@apache.org>.
blackmwk merged PR #2231:
URL: https://github.com/apache/iceberg-rust/pull/2231
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(storage): implement opendal resolving storage [iceberg-rust]
Posted by "blackmwk (via GitHub)" <gi...@apache.org>.
blackmwk commented on code in PR #2231:
URL: https://github.com/apache/iceberg-rust/pull/2231#discussion_r2943897755
##########
crates/storage/opendal/src/resolving.rs:
##########
@@ -0,0 +1,266 @@
+// 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.
+
+//! Resolving storage that auto-detects the scheme from a path and delegates
+//! to the appropriate [`OpenDalStorage`] variant.
+
+use std::collections::HashMap;
+use std::sync::{Arc, RwLock};
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use iceberg::io::{
+ FileMetadata, FileRead, FileWrite, InputFile, OutputFile, Storage, StorageConfig,
+ StorageFactory,
+};
+use iceberg::{Error, ErrorKind, Result};
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+use crate::OpenDalStorage;
+#[cfg(feature = "opendal-s3")]
+use crate::s3::CustomAwsCredentialLoader;
+
+/// Extract the scheme from a path string (e.g., `"s3://bucket/key"` → `"s3"`).
+fn extract_scheme(path: &str) -> Result<String> {
+ let url = Url::parse(path).map_err(|e| {
+ Error::new(
+ ErrorKind::DataInvalid,
+ format!("Invalid path: {path}, failed to parse URL: {e}"),
+ )
+ })?;
+ Ok(url.scheme().to_string())
+}
+
+/// Build an [`OpenDalStorage`] variant for the given scheme and config properties.
+fn build_storage_for_scheme(
+ scheme: &str,
+ props: &HashMap<String, String>,
+ #[cfg(feature = "opendal-s3")] customized_credential_load: &Option<CustomAwsCredentialLoader>,
+) -> Result<OpenDalStorage> {
+ match scheme {
+ #[cfg(feature = "opendal-s3")]
+ "s3" | "s3a" | "s3n" => {
Review Comment:
What I'm saying is as follwoing:
```
/// Opendal S3 storage supported schema
pub const SCHEMA_S3A = "s3a";
pub const SCHEMA_S3N = "s3n";
...
```
So that users could see it in docs.rs .
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(storage): implement opendal resolving storage [iceberg-rust]
Posted by "CTTY (via GitHub)" <gi...@apache.org>.
CTTY commented on code in PR #2231:
URL: https://github.com/apache/iceberg-rust/pull/2231#discussion_r2942061783
##########
crates/storage/opendal/src/resolving.rs:
##########
@@ -0,0 +1,266 @@
+// 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.
+
+//! Resolving storage that auto-detects the scheme from a path and delegates
+//! to the appropriate [`OpenDalStorage`] variant.
+
+use std::collections::HashMap;
+use std::sync::{Arc, RwLock};
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use iceberg::io::{
+ FileMetadata, FileRead, FileWrite, InputFile, OutputFile, Storage, StorageConfig,
+ StorageFactory,
+};
+use iceberg::{Error, ErrorKind, Result};
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+use crate::OpenDalStorage;
+#[cfg(feature = "opendal-s3")]
+use crate::s3::CustomAwsCredentialLoader;
+
+/// Extract the scheme from a path string (e.g., `"s3://bucket/key"` → `"s3"`).
+fn extract_scheme(path: &str) -> Result<String> {
+ let url = Url::parse(path).map_err(|e| {
+ Error::new(
+ ErrorKind::DataInvalid,
+ format!("Invalid path: {path}, failed to parse URL: {e}"),
+ )
+ })?;
+ Ok(url.scheme().to_string())
+}
+
+/// Build an [`OpenDalStorage`] variant for the given scheme and config properties.
+fn build_storage_for_scheme(
+ scheme: &str,
+ props: &HashMap<String, String>,
+ #[cfg(feature = "opendal-s3")] customized_credential_load: &Option<CustomAwsCredentialLoader>,
+) -> Result<OpenDalStorage> {
+ match scheme {
+ #[cfg(feature = "opendal-s3")]
+ "s3" | "s3a" | "s3n" => {
Review Comment:
I think we can use `opendal::Scheme` since we are in the opendal-storage crate. If we add object_store support in the future we can also use `ObjectStoreScheme` from object_store
I've added a `parse_scheme` for this
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(storage): implement opendal resolving storage [iceberg-rust]
Posted by "blackmwk (via GitHub)" <gi...@apache.org>.
blackmwk commented on code in PR #2231:
URL: https://github.com/apache/iceberg-rust/pull/2231#discussion_r2944182233
##########
crates/storage/opendal/src/resolving.rs:
##########
@@ -0,0 +1,266 @@
+// 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.
+
+//! Resolving storage that auto-detects the scheme from a path and delegates
+//! to the appropriate [`OpenDalStorage`] variant.
+
+use std::collections::HashMap;
+use std::sync::{Arc, RwLock};
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use iceberg::io::{
+ FileMetadata, FileRead, FileWrite, InputFile, OutputFile, Storage, StorageConfig,
+ StorageFactory,
+};
+use iceberg::{Error, ErrorKind, Result};
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+use crate::OpenDalStorage;
+#[cfg(feature = "opendal-s3")]
+use crate::s3::CustomAwsCredentialLoader;
+
+/// Extract the scheme from a path string (e.g., `"s3://bucket/key"` → `"s3"`).
+fn extract_scheme(path: &str) -> Result<String> {
+ let url = Url::parse(path).map_err(|e| {
+ Error::new(
+ ErrorKind::DataInvalid,
+ format!("Invalid path: {path}, failed to parse URL: {e}"),
+ )
+ })?;
+ Ok(url.scheme().to_string())
+}
+
+/// Build an [`OpenDalStorage`] variant for the given scheme and config properties.
+fn build_storage_for_scheme(
+ scheme: &str,
+ props: &HashMap<String, String>,
+ #[cfg(feature = "opendal-s3")] customized_credential_load: &Option<CustomAwsCredentialLoader>,
+) -> Result<OpenDalStorage> {
+ match scheme {
+ #[cfg(feature = "opendal-s3")]
+ "s3" | "s3a" | "s3n" => {
+ let config = crate::s3::s3_config_parse(props.clone())?;
+ Ok(OpenDalStorage::S3 {
+ configured_scheme: scheme.to_string(),
+ config: Arc::new(config),
+ customized_credential_load: customized_credential_load.clone(),
+ })
+ }
+ #[cfg(feature = "opendal-gcs")]
+ "gs" => {
+ let config = crate::gcs::gcs_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Gcs {
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-oss")]
+ "oss" => {
+ let config = crate::oss::oss_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Oss {
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-azdls")]
+ "abfs" | "abfss" | "wasb" | "wasbs" => {
+ let configured_scheme: crate::azdls::AzureStorageScheme = scheme.parse()?;
+ let config = crate::azdls::azdls_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Azdls {
+ configured_scheme,
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-fs")]
+ "file" => Ok(OpenDalStorage::LocalFs),
+ #[cfg(feature = "opendal-memory")]
+ "memory" => Ok(OpenDalStorage::Memory(crate::memory::memory_config_build()?)),
+ _ => Err(Error::new(
+ ErrorKind::FeatureUnsupported,
+ format!("Unsupported storage scheme: {scheme}"),
+ )),
+ }
+}
+
+/// A resolving storage factory that creates [`OpenDalResolvingStorage`] instances.
+///
+/// This factory accepts paths from any supported storage system and dynamically
+/// delegates operations to the appropriate [`OpenDalStorage`] variant based on
+/// the path scheme.
+///
+/// # Example
+///
+/// ```rust,ignore
+/// use std::sync::Arc;
+/// use iceberg::io::FileIOBuilder;
+/// use iceberg_storage_opendal::OpenDalResolvingStorageFactory;
+///
+/// let factory = OpenDalResolvingStorageFactory::new();
+/// let file_io = FileIOBuilder::new(Arc::new(factory))
+/// .with_prop("s3.region", "us-east-1")
+/// .build();
+/// ```
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct OpenDalResolvingStorageFactory {
+ /// Custom AWS credential loader for S3 storage.
+ #[cfg(feature = "opendal-s3")]
+ #[serde(skip)]
+ customized_credential_load: Option<CustomAwsCredentialLoader>,
+}
+
+impl Default for OpenDalResolvingStorageFactory {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+impl OpenDalResolvingStorageFactory {
+ /// Create a new resolving storage factory.
+ pub fn new() -> Self {
+ Self {
+ #[cfg(feature = "opendal-s3")]
+ customized_credential_load: None,
+ }
+ }
+
+ /// Set a custom AWS credential loader for S3 storage.
+ #[cfg(feature = "opendal-s3")]
+ pub fn with_s3_credential_loader(mut self, loader: CustomAwsCredentialLoader) -> Self {
+ self.customized_credential_load = Some(loader);
+ self
+ }
+}
+
+#[typetag::serde]
+impl StorageFactory for OpenDalResolvingStorageFactory {
+ fn build(&self, config: &StorageConfig) -> Result<Arc<dyn Storage>> {
+ Ok(Arc::new(OpenDalResolvingStorage {
+ props: config.props().clone(),
+ storages: RwLock::new(HashMap::new()),
+ #[cfg(feature = "opendal-s3")]
+ customized_credential_load: self.customized_credential_load.clone(),
+ }))
+ }
+}
+
+/// A resolving storage that auto-detects the scheme from a path and delegates
+/// to the appropriate [`OpenDalStorage`] variant.
+///
+/// Sub-storages are lazily created on first use for each scheme and cached
+/// for subsequent operations.
+#[derive(Debug, Serialize, Deserialize)]
+pub struct OpenDalResolvingStorage {
+ /// Configuration properties shared across all backends.
+ props: HashMap<String, String>,
+ /// Cache of scheme → storage mappings.
+ #[serde(skip, default)]
+ storages: RwLock<HashMap<String, Arc<OpenDalStorage>>>,
Review Comment:
IIRC the `configured_scheme` was a legacy setting from before we refactor `Storage` trait. I think we no longer need this field since the `Stroage` now accepts the full url. Please create an issue to track it.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(storage): implement opendal resolving storage [iceberg-rust]
Posted by "CTTY (via GitHub)" <gi...@apache.org>.
CTTY commented on code in PR #2231:
URL: https://github.com/apache/iceberg-rust/pull/2231#discussion_r2942082665
##########
crates/storage/opendal/src/resolving.rs:
##########
@@ -0,0 +1,266 @@
+// 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.
+
+//! Resolving storage that auto-detects the scheme from a path and delegates
+//! to the appropriate [`OpenDalStorage`] variant.
+
+use std::collections::HashMap;
+use std::sync::{Arc, RwLock};
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use iceberg::io::{
+ FileMetadata, FileRead, FileWrite, InputFile, OutputFile, Storage, StorageConfig,
+ StorageFactory,
+};
+use iceberg::{Error, ErrorKind, Result};
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+use crate::OpenDalStorage;
+#[cfg(feature = "opendal-s3")]
+use crate::s3::CustomAwsCredentialLoader;
+
+/// Extract the scheme from a path string (e.g., `"s3://bucket/key"` → `"s3"`).
+fn extract_scheme(path: &str) -> Result<String> {
+ let url = Url::parse(path).map_err(|e| {
+ Error::new(
+ ErrorKind::DataInvalid,
+ format!("Invalid path: {path}, failed to parse URL: {e}"),
+ )
+ })?;
+ Ok(url.scheme().to_string())
+}
+
+/// Build an [`OpenDalStorage`] variant for the given scheme and config properties.
+fn build_storage_for_scheme(
+ scheme: &str,
+ props: &HashMap<String, String>,
+ #[cfg(feature = "opendal-s3")] customized_credential_load: &Option<CustomAwsCredentialLoader>,
+) -> Result<OpenDalStorage> {
+ match scheme {
+ #[cfg(feature = "opendal-s3")]
+ "s3" | "s3a" | "s3n" => {
+ let config = crate::s3::s3_config_parse(props.clone())?;
+ Ok(OpenDalStorage::S3 {
+ configured_scheme: scheme.to_string(),
+ config: Arc::new(config),
+ customized_credential_load: customized_credential_load.clone(),
+ })
+ }
+ #[cfg(feature = "opendal-gcs")]
+ "gs" => {
+ let config = crate::gcs::gcs_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Gcs {
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-oss")]
+ "oss" => {
+ let config = crate::oss::oss_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Oss {
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-azdls")]
+ "abfs" | "abfss" | "wasb" | "wasbs" => {
+ let configured_scheme: crate::azdls::AzureStorageScheme = scheme.parse()?;
+ let config = crate::azdls::azdls_config_parse(props.clone())?;
+ Ok(OpenDalStorage::Azdls {
+ configured_scheme,
+ config: Arc::new(config),
+ })
+ }
+ #[cfg(feature = "opendal-fs")]
+ "file" => Ok(OpenDalStorage::LocalFs),
+ #[cfg(feature = "opendal-memory")]
+ "memory" => Ok(OpenDalStorage::Memory(crate::memory::memory_config_build()?)),
+ _ => Err(Error::new(
+ ErrorKind::FeatureUnsupported,
+ format!("Unsupported storage scheme: {scheme}"),
+ )),
+ }
+}
+
+/// A resolving storage factory that creates [`OpenDalResolvingStorage`] instances.
+///
+/// This factory accepts paths from any supported storage system and dynamically
+/// delegates operations to the appropriate [`OpenDalStorage`] variant based on
+/// the path scheme.
+///
+/// # Example
+///
+/// ```rust,ignore
+/// use std::sync::Arc;
+/// use iceberg::io::FileIOBuilder;
+/// use iceberg_storage_opendal::OpenDalResolvingStorageFactory;
+///
+/// let factory = OpenDalResolvingStorageFactory::new();
+/// let file_io = FileIOBuilder::new(Arc::new(factory))
+/// .with_prop("s3.region", "us-east-1")
+/// .build();
+/// ```
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct OpenDalResolvingStorageFactory {
+ /// Custom AWS credential loader for S3 storage.
+ #[cfg(feature = "opendal-s3")]
+ #[serde(skip)]
+ customized_credential_load: Option<CustomAwsCredentialLoader>,
+}
+
+impl Default for OpenDalResolvingStorageFactory {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+impl OpenDalResolvingStorageFactory {
+ /// Create a new resolving storage factory.
+ pub fn new() -> Self {
+ Self {
+ #[cfg(feature = "opendal-s3")]
+ customized_credential_load: None,
+ }
+ }
+
+ /// Set a custom AWS credential loader for S3 storage.
+ #[cfg(feature = "opendal-s3")]
+ pub fn with_s3_credential_loader(mut self, loader: CustomAwsCredentialLoader) -> Self {
+ self.customized_credential_load = Some(loader);
+ self
+ }
+}
+
+#[typetag::serde]
+impl StorageFactory for OpenDalResolvingStorageFactory {
+ fn build(&self, config: &StorageConfig) -> Result<Arc<dyn Storage>> {
+ Ok(Arc::new(OpenDalResolvingStorage {
+ props: config.props().clone(),
+ storages: RwLock::new(HashMap::new()),
+ #[cfg(feature = "opendal-s3")]
+ customized_credential_load: self.customized_credential_load.clone(),
+ }))
+ }
+}
+
+/// A resolving storage that auto-detects the scheme from a path and delegates
+/// to the appropriate [`OpenDalStorage`] variant.
+///
+/// Sub-storages are lazily created on first use for each scheme and cached
+/// for subsequent operations.
+#[derive(Debug, Serialize, Deserialize)]
+pub struct OpenDalResolvingStorage {
+ /// Configuration properties shared across all backends.
+ props: HashMap<String, String>,
+ /// Cache of scheme → storage mappings.
+ #[serde(skip, default)]
+ storages: RwLock<HashMap<String, Arc<OpenDalStorage>>>,
Review Comment:
The key here is a string representing a scheme, you can have both within a map:
```
("s3", OpenDalS3Storage),
("s3a", AnotherOpenDalS3Storage)
```
Or we are thinking of mapping one scheme to multiple storages?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org