This is an automated email from the ASF dual-hosted git repository.

fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new e887fb1  feat: replace 'Builder' with 'TypedBuilder' for 'Snapshot' 
(#110)
e887fb1 is described below

commit e887fb1682c424b29ebcaadfdb462d438f2089b2
Author: Xiaoyang Liu <[email protected]>
AuthorDate: Sat Dec 2 16:46:42 2023 -0800

    feat: replace 'Builder' with 'TypedBuilder' for 'Snapshot' (#110)
    
    * feat: replace 'Builder' with 'TypedBuilder' for 'Snapshot'
    
    Signed-off-by: Xiaoyang Liu <[email protected]>
    
    * fix: revert trailing whitespace
    
    ---------
    
    Signed-off-by: Xiaoyang Liu <[email protected]>
---
 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 b76268a..8037d8c 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::<Vec<_>>());
         assert_eq!(
             &[SnapshotLog {
diff --git a/crates/iceberg/src/catalog/mod.rs 
b/crates/iceberg/src/catalog/mod.rs
index ce3c5e7..d13a46b 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 ad3d3d0..c10e892 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<i64>,
     /// 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<i64>,
 }
 
@@ -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 {
diff --git a/crates/iceberg/src/spec/table_metadata.rs 
b/crates/iceberg/src/spec/table_metadata.rs
index da891ac..905c823 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,

Reply via email to