emkornfield commented on code in PR #1876:
URL: https://github.com/apache/iceberg-rust/pull/1876#discussion_r2625288838


##########
crates/iceberg/src/spec/table_metadata.rs:
##########
@@ -461,9 +463,58 @@ impl TableMetadata {
         file_io: &FileIO,
         metadata_location: impl AsRef<str>,
     ) -> Result<()> {
+        let json_data = serde_json::to_vec(self)?;
+
+        // Check if compression is enabled via table properties
+        let codec = self
+            .properties
+            .get(TableProperties::PROPERTY_METADATA_COMPRESSION_CODEC)
+            .map(|s| s.as_str());
+
+        // Use case-insensitive comparison to match Java implementation
+        let (data_to_write, actual_location) = match codec.map(|s| 
s.to_lowercase()).as_deref() {
+            Some("gzip") => {
+                let mut encoder = GzEncoder::new(Vec::new(), 
flate2::Compression::default());
+                encoder.write_all(&json_data).map_err(|e| {
+                    Error::new(
+                        ErrorKind::DataInvalid,
+                        "Failed to compress metadata with gzip",
+                    )
+                    .with_source(e)
+                })?;
+                let compressed_data = encoder.finish().map_err(|e| {
+                    Error::new(ErrorKind::DataInvalid, "Failed to finish gzip 
compression")
+                        .with_source(e)
+                })?;
+
+                // Modify filename to add .gz before .metadata.json
+                let location = metadata_location.as_ref();
+                let new_location = if location.ends_with(".gz.metadata.json") {

Review Comment:
   an alternative is we could reverse this logic and base compression on 
whether the the path matches this pattern.



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