liurenjie1024 commented on PR #62:
URL: https://github.com/apache/iceberg-rust/pull/62#issuecomment-1732912580

   > How about a method like this for the 'CREATE TABLE' case? (For this method 
to compile, a few modification and addition is needed in other modules, like 
adding Error conversion, etc. And this method has not been tested yet.)
   > 
   > ```rust
   > impl TableMetadata {
   >     /// New struct to create a table
   >     pub fn try_new_to_create_table(table_creation: TableCreation) -> 
Result<Self, Error> {
   >         let last_column_id = table_creation.schema.highest_field_id();
   >         let current_schema_id = table_creation.schema.schema_id();
   >         let schemas = HashMap::from([(
   >             table_creation.schema.schema_id(),
   >             Arc::new(table_creation.schema),
   >         )]);
   >         let default_spec_id;
   >         let partition_specs;
   >         let last_partition_id;
   >         match table_creation.partition_spec {
   >             Some(partition_spec) => {
   >                 default_spec_id = partition_spec.spec_id;
   >                 last_partition_id =
   >                     max(partition_spec.fields.iter().map(|field| 
field.field_id)).unwrap_or(-1);
   >                 partition_specs = HashMap::from([(partition_spec.spec_id, 
partition_spec)]);
   >             }
   >             None => {
   >                 default_spec_id = 0;
   >                 last_partition_id = -1;
   >                 partition_specs = HashMap::from([(
   >                     default_spec_id,
   >                     PartitionSpec::builder()
   >                         .with_spec_id(0)
   >                         .with_fields(vec![])
   >                         .build()?,
   >                 )]);
   >             }
   >         }
   >         let default_sort_order_id = table_creation.sort_order.order_id;
   >         let sort_orders = HashMap::from([(default_sort_order_id, 
table_creation.sort_order)]);
   >         Ok(Self {
   >             format_version: FormatVersion::V2,
   >             table_uuid: Uuid::new_v4(),
   >             location: table_creation.location,
   >             last_sequence_number: -1,
   >             last_updated_ms: since_the_epoch_as_millis()?,
   >             last_column_id,
   >             schemas,
   >             current_schema_id,
   >             partition_specs,
   >             default_spec_id,
   >             last_partition_id,
   >             properties: table_creation.properties,
   >             current_snapshot_id: None,
   >             snapshots: None,
   >             snapshot_log: vec![],
   >             metadata_log: vec![],
   >             sort_orders,
   >             default_sort_order_id,
   >             refs: HashMap::new(),
   >         })
   >     }
   >     ...
   > }
   > 
   > fn since_the_epoch_as_millis() -> Result<i64, Error> {
   >     let start = SystemTime::now();
   >     let since_the_epoch = start.duration_since(UNIX_EPOCH)?;
   >     Ok(since_the_epoch.as_millis().try_into()?)
   > }
   > ```
   
   This is a builder tailored for `CreateTable`,  why not just put the check in 
builder?


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