Skip to content

Commit 076b8cf

Browse files
committed
Manifest inspect
1 parent b4f899b commit 076b8cf

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

icechunk/src/inspect.rs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
55
use crate::{
66
asset_manager::AssetManager,
77
format::{
8-
SnapshotId,
8+
ManifestId, SnapshotId,
99
manifest::ManifestRef,
1010
snapshot::{
1111
ManifestFileInfo, NodeData, NodeSnapshot, NodeType, SnapshotProperties,
@@ -91,6 +91,40 @@ struct SnapshotInfoInspect {
9191
nodes: Vec<NodeSnapshotInspect>,
9292
}
9393

94+
#[derive(Debug, Serialize, Deserialize)]
95+
struct ArrayManifestInspect {
96+
node_id: String,
97+
num_chunks: u64,
98+
}
99+
100+
#[derive(Debug, Serialize, Deserialize)]
101+
struct ManifestInfoInspect {
102+
id: String,
103+
arrays: Vec<ArrayManifestInspect>,
104+
}
105+
106+
async fn inspect_manifest(
107+
asset_manager: &AssetManager,
108+
id: &ManifestId,
109+
) -> RepositoryResult<ManifestInfoInspect> {
110+
todo!()
111+
}
112+
113+
pub async fn manifest_json(
114+
asset_manager: &AssetManager,
115+
id: &ManifestId,
116+
pretty: bool,
117+
) -> RepositoryResult<String> {
118+
let info = inspect_manifest(asset_manager, id).await?;
119+
let res = if pretty {
120+
serde_json::to_string_pretty(&info)
121+
} else {
122+
serde_json::to_string(&info)
123+
}
124+
.map_err(|e| RepositoryErrorKind::Other(e.to_string()))?;
125+
Ok(res)
126+
}
127+
94128
async fn inspect_snapshot(
95129
asset_manager: &AssetManager,
96130
id: &SnapshotId,
@@ -156,4 +190,30 @@ mod tests {
156190

157191
Ok(())
158192
}
193+
194+
#[icechunk_macros::tokio_test]
195+
async fn test_print_manifest() -> Result<(), Box<dyn std::error::Error>> {
196+
let st = Arc::new(
197+
ObjectStorage::new_local_filesystem(&PathBuf::from(
198+
"../icechunk-python/tests/data/split-repo",
199+
))
200+
.await?,
201+
);
202+
let repo = Repository::open(None, st, Default::default()).await?;
203+
let snap = repo
204+
.ancestry(&VersionInfo::BranchTipRef("main".to_string()))
205+
.await?
206+
.boxed()
207+
.try_next()
208+
.await?
209+
.unwrap();
210+
211+
let manifest_id = &snap.manifests[0].id;
212+
213+
let json = manifest_json(repo.asset_manager(), manifest_id, true).await?;
214+
let info: ManifestInfoInspect = serde_json::from_str(json.as_str())?;
215+
assert!(info.id == manifest_id.to_string());
216+
217+
Ok(())
218+
}
159219
}

0 commit comments

Comments
 (0)