From e887fb1682c424b29ebcaadfdb462d438f2089b2 Mon Sep 17 00:00:00 2001 From: Xiaoyang Liu Date: Sat, 2 Dec 2023 16:46:42 -0800 Subject: [PATCH] feat: replace 'Builder' with 'TypedBuilder' for 'Snapshot' (#110) * feat: replace 'Builder' with 'TypedBuilder' for 'Snapshot' Signed-off-by: Xiaoyang Liu * fix: revert trailing whitespace --------- Signed-off-by: Xiaoyang Liu --- crates/catalog/rest/src/catalog.rs | 2 +- crates/iceberg/src/catalog/mod.rs | 3 +-- crates/iceberg/src/spec/snapshot.rs | 13 +++++-------- crates/iceberg/src/spec/table_metadata.rs | 8 +++----- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/crates/catalog/rest/src/catalog.rs b/crates/catalog/rest/src/catalog.rs index b76268ab7..8037d8c6b 100644 --- a/crates/catalog/rest/src/catalog.rs +++ b/crates/catalog/rest/src/catalog.rs @@ -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::>()); assert_eq!( &[SnapshotLog { diff --git a/crates/iceberg/src/catalog/mod.rs b/crates/iceberg/src/catalog/mod.rs index ce3c5e7a0..d13a46bdb 100644 --- a/crates/iceberg/src/catalog/mod.rs +++ b/crates/iceberg/src/catalog/mod.rs @@ -923,8 +923,7 @@ mod tests { operation: Operation::Append, other: HashMap::default(), }) - .build() - .unwrap(), + .build(), }; test_serde_json(json, update); diff --git a/crates/iceberg/src/spec/snapshot.rs b/crates/iceberg/src/spec/snapshot.rs index ad3d3d012..c10e892bf 100644 --- a/crates/iceberg/src/spec/snapshot.rs +++ b/crates/iceberg/src/spec/snapshot.rs @@ -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; @@ -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, /// A monotonically increasing long that tracks the order of /// changes to a table. @@ -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, } @@ -122,10 +123,6 @@ impl Snapshot { pub fn timestamp(&self) -> DateTime { Utc.timestamp_millis_opt(self.timestamp_ms).unwrap() } - /// Create snapshot builder - pub fn builder() -> SnapshotBuilder { - SnapshotBuilder::default() - } pub(crate) fn log(&self) -> SnapshotLog { SnapshotLog { diff --git a/crates/iceberg/src/spec/table_metadata.rs b/crates/iceberg/src/spec/table_metadata.rs index da891ac2d..905c82307 100644 --- a/crates/iceberg/src/spec/table_metadata.rs +++ b/crates/iceberg/src/spec/table_metadata.rs @@ -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, @@ -1200,8 +1200,7 @@ mod tests { operation: Operation::Append, other: HashMap::new(), }) - .build() - .unwrap(); + .build(); let snapshot2 = Snapshot::builder() .with_snapshot_id(3055729675574597004) @@ -1216,8 +1215,7 @@ mod tests { operation: Operation::Append, other: HashMap::new(), }) - .build() - .unwrap(); + .build(); let expected = TableMetadata { format_version: FormatVersion::V2,