liurenjie1024 commented on code in PR #1802:
URL: https://github.com/apache/iceberg-rust/pull/1802#discussion_r2480595816


##########
crates/iceberg/src/spec/table_metadata.rs:
##########
@@ -413,9 +415,24 @@ impl TableMetadata {
         file_io: &FileIO,
         metadata_location: impl AsRef<str>,
     ) -> Result<TableMetadata> {
-        let input_file = file_io.new_input(metadata_location)?;
+        let input_file = file_io.new_input(metadata_location.as_ref())?;
         let metadata_content = input_file.read().await?;
-        let metadata = 
serde_json::from_slice::<TableMetadata>(&metadata_content)?;
+
+        // Check if the file is compressed by looking for the gzip "magic 
number".
+        let metadata = if metadata_content.len() > 2
+            && metadata_content[0] == 0x1F
+            && metadata_content[1] == 0x8B
+        {
+            let mut decoder = GzDecoder::new(metadata_content.as_ref());
+            let mut decompressed_data = Vec::new();
+            decoder
+                .read_to_end(&mut decompressed_data)
+                .map_err(|e| Error::new(ErrorKind::DataInvalid, 
e.to_string()))?;

Review Comment:
   ```suggestion
                   .map_err(|e| Error::new(ErrorKind::DataInvalid, "Trying to 
read compressed metadata file").with_context("file_path", 
metadata_location).with_source(e)
                   )?;
   ```



##########
crates/iceberg/src/spec/table_metadata.rs:
##########
@@ -413,9 +415,24 @@ impl TableMetadata {
         file_io: &FileIO,
         metadata_location: impl AsRef<str>,
     ) -> Result<TableMetadata> {
-        let input_file = file_io.new_input(metadata_location)?;
+        let input_file = file_io.new_input(metadata_location.as_ref())?;
         let metadata_content = input_file.read().await?;
-        let metadata = 
serde_json::from_slice::<TableMetadata>(&metadata_content)?;
+
+        // Check if the file is compressed by looking for the gzip "magic 
number".
+        let metadata = if metadata_content.len() > 2
+            && metadata_content[0] == 0x1F
+            && metadata_content[1] == 0x8B
+        {

Review Comment:
   Add a debug log here to explain why we choose to use try to decompress it?



##########
crates/iceberg/src/spec/table_metadata.rs:
##########
@@ -413,9 +415,24 @@ impl TableMetadata {
         file_io: &FileIO,
         metadata_location: impl AsRef<str>,
     ) -> Result<TableMetadata> {
-        let input_file = file_io.new_input(metadata_location)?;
+        let input_file = file_io.new_input(metadata_location.as_ref())?;
         let metadata_content = input_file.read().await?;
-        let metadata = 
serde_json::from_slice::<TableMetadata>(&metadata_content)?;
+
+        // Check if the file is compressed by looking for the gzip "magic 
number".
+        let metadata = if metadata_content.len() > 2
+            && metadata_content[0] == 0x1F
+            && metadata_content[1] == 0x8B
+        {
+            let mut decoder = GzDecoder::new(metadata_content.as_ref());
+            let mut decompressed_data = Vec::new();
+            decoder
+                .read_to_end(&mut decompressed_data)
+                .map_err(|e| Error::new(ErrorKind::DataInvalid, 
e.to_string()))?;

Review Comment:
   To make error reporting better.



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