Skip to content

Commit 86abf7c

Browse files
committed
feat: decompress gzip compressed metadata files
1 parent be5f609 commit 86abf7c

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iceberg-rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ async-trait = { workspace = true }
1616
bytes = { workspace = true }
1717
derive-getters = { workspace = true }
1818
derive_builder = { workspace = true }
19+
flate2 = { version = "1.1", features = ["zlib-rs"], default-features = false }
1920
futures = { workspace = true }
2021
getrandom = { workspace = true }
2122
iceberg-rust-spec = { path = "../iceberg-rust-spec", version = "0.7.0" }

iceberg-rust/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ pub enum Error {
2020
/// Conversion error
2121
#[error("Failed to convert {0} to {1}.")]
2222
Conversion(String, String),
23+
/// Failed to decompress gzip data
24+
#[error("Failed to decompress gzip data: {0}")]
25+
Decompress(String),
2326
/// Not found
2427
#[error("{0} not found.")]
2528
NotFound(String),

iceberg-rust/src/object_store/store.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use iceberg_rust_spec::{
88
use object_store::{Attributes, ObjectStore, PutOptions, TagSet};
99

1010
use crate::error::Error;
11+
use flate2::read::GzDecoder;
12+
use std::io::Read;
1113

1214
/// Simplify interaction with iceberg files
1315
#[async_trait]
@@ -32,7 +34,16 @@ impl<T: ObjectStore> IcebergStore for T {
3234
.await?
3335
.bytes()
3436
.await?;
35-
serde_json::from_slice(&bytes).map_err(Error::from)
37+
38+
if location.ends_with(".gz.metadata.json") {
39+
let mut decoder = GzDecoder::new(&bytes[..]);
40+
let mut decompressed_data = Vec::new();
41+
decoder.read_to_end(&mut decompressed_data)
42+
.map_err(|e| Error::Decompress(e.to_string()))?;
43+
serde_json::from_slice(&decompressed_data).map_err(Error::from)
44+
} else {
45+
serde_json::from_slice(&bytes).map_err(Error::from)
46+
}
3647
}
3748

3849
async fn put_metadata(

0 commit comments

Comments
 (0)