Skip to content

Commit

Permalink
feat: replace 'Builder' with 'TypedBuilder' for 'Snapshot' (#110)
Browse files Browse the repository at this point in the history
* feat: replace 'Builder' with 'TypedBuilder' for 'Snapshot'

Signed-off-by: Xiaoyang Liu <siujoeng.lau@gmail.com>

* fix: revert trailing whitespace

---------

Signed-off-by: Xiaoyang Liu <siujoeng.lau@gmail.com>
  • Loading branch information
xiaoyang-sde authored Dec 3, 2023
1 parent 7108b4a commit e887fb1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion crates/catalog/rest/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ mod tests {
("total-position-deletes", "0"),
("total-equality-deletes", "0")
].iter().map(|p| (p.0.to_string(), p.1.to_string()))),
}).build().unwrap()
}).build()
)], table.metadata().snapshots().collect::<Vec<_>>());
assert_eq!(
&[SnapshotLog {
Expand Down
3 changes: 1 addition & 2 deletions crates/iceberg/src/catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,7 @@ mod tests {
operation: Operation::Append,
other: HashMap::default(),
})
.build()
.unwrap(),
.build(),
};

test_serde_json(json, update);
Expand Down
13 changes: 5 additions & 8 deletions crates/iceberg/src/spec/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use chrono::{DateTime, TimeZone, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::sync::Arc;
use typed_builder::TypedBuilder;

use super::table_metadata::SnapshotLog;
use _serde::SnapshotV2;
Expand Down Expand Up @@ -59,16 +60,16 @@ impl Default for Operation {
}
}

#[derive(Debug, PartialEq, Eq, Clone, Builder, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, TypedBuilder)]
#[serde(from = "SnapshotV2", into = "SnapshotV2")]
#[builder(setter(prefix = "with"))]
#[builder(field_defaults(setter(prefix = "with_")))]
/// A snapshot represents the state of a table at some time and is used to access the complete set of data files in the table.
pub struct Snapshot {
/// A unique long ID
snapshot_id: i64,
/// The snapshot ID of the snapshot’s parent.
/// Omitted for any snapshot with no parent
#[builder(default = "None")]
#[builder(default = None)]
parent_snapshot_id: Option<i64>,
/// A monotonically increasing long that tracks the order of
/// changes to a table.
Expand All @@ -82,7 +83,7 @@ pub struct Snapshot {
/// A string map that summarizes the snapshot changes, including operation.
summary: Summary,
/// ID of the table’s current schema when the snapshot was created.
#[builder(setter(strip_option), default = "None")]
#[builder(setter(strip_option), default = None)]
schema_id: Option<i64>,
}

Expand Down Expand Up @@ -122,10 +123,6 @@ impl Snapshot {
pub fn timestamp(&self) -> DateTime<Utc> {
Utc.timestamp_millis_opt(self.timestamp_ms).unwrap()
}
/// Create snapshot builder
pub fn builder() -> SnapshotBuilder {
SnapshotBuilder::default()
}

pub(crate) fn log(&self) -> SnapshotLog {
SnapshotLog {
Expand Down
8 changes: 3 additions & 5 deletions crates/iceberg/src/spec/table_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ mod tests {
.with_schema_id(0)
.with_manifest_list(ManifestListLocation::ManifestListFile("/home/iceberg/warehouse/nyc/taxis/metadata/snap-638933773299822130-1-7e6760f0-4f6c-4b23-b907-0a5a174e3863.avro".to_string()))
.with_summary(Summary { operation: Operation::Append, other: HashMap::from_iter(vec![("spark.app.id".to_string(), "local-1662532784305".to_string()), ("added-data-files".to_string(), "4".to_string()), ("added-records".to_string(), "4".to_string()), ("added-files-size".to_string(), "6001".to_string())]) })
.build().unwrap();
.build();

let expected = TableMetadata {
format_version: FormatVersion::V1,
Expand Down Expand Up @@ -1200,8 +1200,7 @@ mod tests {
operation: Operation::Append,
other: HashMap::new(),
})
.build()
.unwrap();
.build();

let snapshot2 = Snapshot::builder()
.with_snapshot_id(3055729675574597004)
Expand All @@ -1216,8 +1215,7 @@ mod tests {
operation: Operation::Append,
other: HashMap::new(),
})
.build()
.unwrap();
.build();

let expected = TableMetadata {
format_version: FormatVersion::V2,
Expand Down

0 comments on commit e887fb1

Please sign in to comment.