y0psolo commented on code in PR #62: URL: https://github.com/apache/iceberg-rust/pull/62#discussion_r1349567865
########## crates/iceberg/src/spec/table_metadata.rs: ########## @@ -93,22 +112,291 @@ pub struct TableMetadata { /// previous metadata file location should be added to the list. /// Tables can be configured to remove oldest metadata log entries and /// keep a fixed-size log of the most recent entries after a commit. + #[builder(default)] metadata_log: Vec<MetadataLog>, /// A list of sort orders, stored as full sort order objects. + #[builder(default)] sort_orders: HashMap<i64, SortOrder>, /// Default sort order id of the table. Note that this could be used by /// writers, but is not used when reading because reads use the specs /// stored in manifest files. + #[builder(default = "DEFAULT_SORT_ORDER_ID")] default_sort_order_id: i64, ///A map of snapshot references. The map keys are the unique snapshot reference /// names in the table, and the map values are snapshot reference objects. /// There is always a main branch reference pointing to the current-snapshot-id /// even if the refs map is null. + #[builder(default)] refs: HashMap<String, SnapshotReference>, } +// We define a from implementation from builder Error to Iceberg Error +impl From<UninitializedFieldError> for Error { + fn from(ufe: UninitializedFieldError) -> Error { + Error::new(ErrorKind::DataInvalid, ufe.to_string()) + } +} + +impl TableMetadataBuilder { + /// Initialize a TableMetadata with a TableCreation struct + /// the Schema, sortOrder and PartitionSpec will be set as current + pub fn with_table_creation(&mut self, tc: TableCreation) -> &mut Self { + self.with_location(tc.location) + .with_properties(tc.properties) + .with_sort_order(tc.sort_order, true) + .with_schema(tc.schema, true); + + if let Some(partition_spec) = tc.partition_spec { + self.with_partition_spec(partition_spec, true); + } + self + } + + /// Add a schema to the TableMetadata + /// schema : Schema to be added or replaced + /// current : True if the schema is the current one + pub fn with_schema(&mut self, schema: Schema, current: bool) -> &mut Self { Review Comment: i could update it each time we have modification, but does it should be updated in theory at write time from what i read in spec ? -- 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