plusplusjiajia commented on code in PR #2651:
URL: https://github.com/apache/iceberg-rust/pull/2651#discussion_r4456452685


##########
crates/storage/opendal/src/lib.rs:
##########
@@ -223,8 +227,14 @@ where
 
 #[typetag::serde(name = "OpenDalStorageFactory")]
 impl StorageFactory for OpenDalStorageFactory {
-    #[allow(unused_variables)]
     fn build(&self, config: &StorageConfig) -> Result<Arc<dyn Storage>> {
+        PrefixedStorage::build(config, |config| self.build_storage(config))
+    }
+}
+
+impl OpenDalStorageFactory {
+    #[allow(unused_variables)]
+    fn build_storage(&self, config: &StorageConfig) -> Result<Arc<dyn 
Storage>> {

Review Comment:
   Done, it now returns `OpenDalStorage`.



##########
crates/storage/opendal/src/prefixed.rs:
##########
@@ -0,0 +1,379 @@
+// 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.
+
+//! Storage that serves each location with its prefix's credential.
+
+use std::collections::HashMap;
+use std::fmt::{self, Debug};
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use futures::StreamExt;
+use futures::stream::{self, BoxStream};
+use iceberg::Result;
+use iceberg::io::{
+    FileMetadata, FileRead, FileWrite, InputFile, OutputFile, Storage, 
StorageConfig,
+};
+use serde::{Deserialize, Serialize};
+
+/// Per-prefix batch size of `delete_stream`, as in Java's 
`S3FileIO.deleteFiles`.
+const DELETE_BATCH_SIZE: usize = 1000;
+
+/// Serves each path with the credential of its longest matching prefix, as
+/// Java's `S3FileIO.clientForStoragePath` does, else without credentials.
+#[derive(Serialize, Deserialize)]
+pub(crate) struct PrefixedStorage {
+    default: Arc<dyn Storage>,
+    /// Longest prefix first.
+    prefixed: Vec<(String, Arc<dyn Storage>)>,

Review Comment:
   Done. The resolving storage isn't an `OpenDalStorage`, so it now holds a 
`PrefixedStorage` per scheme instead of being wrapped in one.



##########
crates/storage/opendal/src/prefixed.rs:
##########
@@ -0,0 +1,379 @@
+// 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.
+
+//! Storage that serves each location with its prefix's credential.
+
+use std::collections::HashMap;
+use std::fmt::{self, Debug};
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use futures::StreamExt;
+use futures::stream::{self, BoxStream};
+use iceberg::Result;
+use iceberg::io::{
+    FileMetadata, FileRead, FileWrite, InputFile, OutputFile, Storage, 
StorageConfig,
+};
+use serde::{Deserialize, Serialize};
+
+/// Per-prefix batch size of `delete_stream`, as in Java's 
`S3FileIO.deleteFiles`.
+const DELETE_BATCH_SIZE: usize = 1000;
+
+/// Serves each path with the credential of its longest matching prefix, as
+/// Java's `S3FileIO.clientForStoragePath` does, else without credentials.
+#[derive(Serialize, Deserialize)]
+pub(crate) struct PrefixedStorage {
+    default: Arc<dyn Storage>,
+    /// Longest prefix first.
+    prefixed: Vec<(String, Arc<dyn Storage>)>,
+}
+
+impl PrefixedStorage {
+    /// Builds the storage for `config` with `build`, which is passed configs
+    /// without storage credentials.
+    pub(crate) fn build(
+        config: &StorageConfig,
+        build: impl Fn(&StorageConfig) -> Result<Arc<dyn Storage>>,

Review Comment:
   Done.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to