liurenjie1024 commented on code in PR #262:
URL: https://github.com/apache/iceberg-rust/pull/262#discussion_r1524213529


##########
crates/iceberg/src/spec/table_metadata.rs:
##########
@@ -275,6 +277,82 @@ impl TableMetadata {
     }
 }
 
+/// Manipulating table metadata.
+pub struct TableMetadataBuilder(TableMetadata);
+
+impl TableMetadataBuilder {
+    /// Creates a new table metadata builder from the given table metadata.
+    pub fn new(origin: TableMetadata) -> Self {
+        Self(origin)
+    }
+
+    /// Creates a new table metadata builder from the given table creation.
+    pub fn from_table_creation(table_creation: TableCreation) -> Result<Self> {
+        let TableCreation {
+            name: _,
+            location,
+            schema,
+            partition_spec,
+            sort_order,
+            properties,
+        } = table_creation;
+
+        if partition_spec.is_some() {
+            return Err(Error::new(
+                ErrorKind::FeatureUnsupported,
+                "Can't create table with partition spec now",
+            ));
+        }
+
+        if sort_order.is_some() {
+            return Err(Error::new(
+                ErrorKind::FeatureUnsupported,
+                "Can't create table with sort order now",
+            ));
+        }
+
+        let table_metadata = TableMetadata {
+            format_version: FormatVersion::V2,
+            table_uuid: Uuid::new_v4(),
+            location: location.ok_or_else(|| {
+                Error::new(
+                    ErrorKind::DataInvalid,
+                    "Can't create table without location",
+                )
+            })?,
+            last_sequence_number: 0,
+            last_updated_ms: Utc::now().timestamp_millis(),
+            last_column_id: schema.highest_field_id(),
+            current_schema_id: schema.schema_id(),
+            schemas: HashMap::from([(schema.schema_id(), Arc::new(schema))]),
+            partition_specs: Default::default(),
+            default_spec_id: 0,
+            last_partition_id: 0,
+            properties,
+            current_snapshot_id: None,
+            snapshots: Default::default(),
+            snapshot_log: vec![],
+            sort_orders: Default::default(),
+            metadata_log: vec![],
+            default_sort_order_id: 0,
+            refs: Default::default(),
+        };
+
+        Ok(Self(table_metadata))
+    }
+
+    /// Changes uuid of table metadata.
+    pub fn assign_uuid(mut self, uuid: Uuid) -> Result<Self> {

Review Comment:
   Currently it's only used here, but it's also intended for user to construct 
table metadata, so I think it's ok to leave it `pub`



-- 
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