xiaoyang-sde commented on issue #88:
URL: https://github.com/apache/iceberg-rust/issues/88#issuecomment-1829169593

   Hi! I'm learning Apache Iceberg and I think this issue might be a good 
starting point to learn about the source code.
   I noticed that `PartitionSpec`, `Snapshot`, and `SortOrder` are still using 
the `derive_build` macros, and I figured out a solution to migrate them to 
`TypedBuilder`.
   
   - `Snapshot` is straightforward:
   
   ```diff
   
   -#[derive(Debug, PartialEq, Eq, Clone, Builder, Serialize, Deserialize)]
   +#[derive(Debug, PartialEq, Eq, Clone, TypedBuilder, Serialize, Deserialize)]
    #[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>,
    }
   ```
   
   - `PartitionSpec` is a bit complex, because we need to explicitly define the 
`with_fields` and `with_partition_field` methods
   
   ```diff
   
   -#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Default, 
Builder)]
   +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Default, 
TypedBuilder)]
    #[serde(rename_all = "kebab-case")]
   -#[builder(setter(prefix = "with"))]
   +#[builder(field_defaults(setter(prefix = "with_")))]
    ///  Partition spec that defines how to produce a tuple of partition values 
from a record.
    pub struct PartitionSpec {
        /// Identifier for PartitionSpec
        pub spec_id: i32,
        /// Details of the partition spec
   -    #[builder(setter(each(name = "with_partition_field")))]
   -    pub fields: Vec<PartitionField>,
   
   +    #[builder(mutators(
   +        pub fn with_fields(self, fields: Vec<PartitionField>) {
   +            self.fields.extend(fields)
   +        }
   +
   +        pub fn with_partition_field(self, field: PartitionField) {
   +            self.fields.push(field)
   +        }
   +    ), default, via_mutators)]
   +    pub fields: Vec<PartitionField>,
    }
   ```
   
   - `SortOrder` is similar to `PartitionSpec`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to