use crate::proto::{GetLakeSnapshotResponse, PbLakeSnapshotForBucket};
use crate::{BucketId, PartitionId, SnapshotId, TableId};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LakeBucketSnapshot {
pub partition_id: Option<PartitionId>,
pub bucket_id: BucketId,
pub log_offset: Option<i64>,
pub partition_name: Option<String>,
}
impl LakeBucketSnapshot {
pub fn from_pb(pb: &PbLakeSnapshotForBucket) -> Self {
Self {
partition_id: pb.partition_id,
bucket_id: pb.bucket_id,
log_offset: pb.log_offset,
partition_name: pb.partition_name.clone(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LakeSnapshotInfo {
pub table_id: TableId,
pub snapshot_id: SnapshotId,
pub bucket_snapshots: Vec<LakeBucketSnapshot>,
}
impl LakeSnapshotInfo {
pub fn from_pb(pb: &GetLakeSnapshotResponse) -> Self {
Self {
table_id: pb.table_id,
snapshot_id: pb.snapshot_id,
bucket_snapshots: pb
.bucket_snapshots
.iter()
.map(LakeBucketSnapshot::from_pb)
.collect(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_lake_bucket_snapshot_from_pb() {
let pb = PbLakeSnapshotForBucket {
partition_id: Some(1),
bucket_id: 2,
log_offset: Some(3),
partition_name: Some("date=2024-01-01".to_string()),
};
let s = LakeBucketSnapshot::from_pb(&pb);
assert_eq!(s.bucket_id, 2);
assert_eq!(s.partition_id, Some(1));
assert_eq!(s.log_offset, Some(3));
assert_eq!(s.partition_name.as_deref(), Some("date=2024-01-01"));
}
}