blackmwk commented on code in PR #3090:
URL: https://github.com/apache/iceberg-rust/pull/3090#discussion_r3891322502


##########
crates/iceberg/src/io/file_io.rs:
##########
@@ -41,6 +42,20 @@ use crate::Result;
 /// OSS, Azure, etc.), use the
 /// 
[`iceberg-storage-opendal`](https://crates.io/crates/iceberg-storage-opendal) 
crate.
 ///
+/// # Serialization
+///
+/// `FileIO` serializes its storage configuration and factory, but not its 
cached storage
+/// instance. The storage cache is rebuilt lazily on first use after 
deserialization.
+///
+/// All storage configuration properties are included in the serialized 
representation. These
+/// properties may contain credentials or other sensitive values, so 
serialized `FileIO` data
+/// must be protected in transit and at rest by the application embedding this 
crate.
+///
+/// Storage factories are serialized through 
[`typetag`](https://docs.rs/typetag). The receiving
+/// binary must link the concrete factory implementation so it is registered 
for deserialization.
+/// Third-party factories must use `#[typetag::serde]` on their 
[`StorageFactory`]
+/// implementation.
+///

Review Comment:
   We should add statement that there is not guarantee about the serialization 
format, and it changes from version to version.



##########
crates/storage/opendal/src/resolving.rs:
##########
@@ -140,6 +140,12 @@ fn build_storage_for_scheme(
 /// delegates operations to the appropriate [`OpenDalStorage`] variant based on
 /// the path scheme.
 ///
+/// # Serialization

Review Comment:
   No, customized credential loader should fail. Also I want to see ut about 
failure.



##########
crates/storage/opendal/tests/file_io_serialization_test.rs:
##########
@@ -0,0 +1,188 @@
+// 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::sync::Arc;
+
+use iceberg::io::{FileIO, FileIOBuilder, StorageFactory};
+use iceberg_storage_opendal::OpenDalResolvingStorageFactory;
+#[cfg(any(
+    feature = "opendal-memory",
+    feature = "opendal-fs",
+    feature = "opendal-s3",
+    feature = "opendal-gcs",
+    feature = "opendal-oss",
+    feature = "opendal-azdls",
+    feature = "opendal-hf"
+))]
+use iceberg_storage_opendal::OpenDalStorageFactory;
+use serde_json::{Value, json};
+
+fn assert_file_io_roundtrip(factory: Arc<dyn StorageFactory>, 
expected_factory: Value) {
+    let file_io = FileIOBuilder::new(factory)
+        .with_prop("test-property", "test-value")
+        .build();
+
+    let serialized = serde_json::to_value(&file_io).unwrap();
+    assert_eq!(
+        serialized,
+        json!({
+            "config": {"props": {"test-property": "test-value"}},
+            "factory": expected_factory
+        })
+    );
+
+    let deserialized: FileIO = 
serde_json::from_value(serialized.clone()).unwrap();
+    assert_eq!(
+        deserialized.config().get("test-property"),
+        Some(&"test-value".to_string())
+    );
+    assert_eq!(serde_json::to_value(deserialized).unwrap(), serialized);
+}
+
+#[test]
+fn test_resolving_factory_serialization_roundtrip() {
+    assert_file_io_roundtrip(
+        Arc::new(OpenDalResolvingStorageFactory::new()),
+        json!({"type": "OpenDalResolvingStorageFactory"}),
+    );
+}
+
+#[cfg(feature = "opendal-memory")]
+#[test]
+fn test_memory_factory_serialization_roundtrip() {
+    assert_file_io_roundtrip(
+        Arc::new(OpenDalStorageFactory::Memory),
+        json!({"type": "OpenDalStorageFactory", "Memory": null}),
+    );
+}
+
+#[cfg(feature = "opendal-fs")]
+#[test]
+fn test_fs_factory_serialization_roundtrip() {
+    assert_file_io_roundtrip(
+        Arc::new(OpenDalStorageFactory::Fs),
+        json!({"type": "OpenDalStorageFactory", "Fs": null}),
+    );
+}
+
+#[cfg(feature = "opendal-s3")]
+#[test]
+fn test_s3_factory_serialization_roundtrip() {

Review Comment:
   I want to see true ser/de tests go to each it mod for differnt backends, and 
see io execution after deserialization



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