laskoviymishka commented on code in PR #3057:
URL: https://github.com/apache/iceberg-rust/pull/3057#discussion_r4531335728


##########
crates/iceberg/src/spec/table_metadata_builder.rs:
##########
@@ -1235,6 +1316,32 @@ impl TableMetadataBuilder {
             .collect()
     }
 
+    /// Gives each field of `spec` the highest id an equivalent field has in 
the table's specs, or
+    /// the next id above `last_partition_id`.
+    fn reassign_partition_field_ids(&self, spec: PartitionSpec) -> 
Result<UnboundPartitionSpec> {
+        let mut field_ids = Self::highest_equivalent_field_ids(
+            self.metadata
+                .partition_specs
+                .values()
+                .flat_map(|spec| spec.fields()),
+        );
+        let mut last_partition_id = self.metadata.last_partition_id;
+
+        let fields = spec.fields().iter().map(|field| {
+            let field_id = *field_ids
+                .entry((vec![field.source_id], field.transform))
+                .or_insert_with(|| {
+                    last_partition_id += 1;

Review Comment:
   you're right, withdrawn. With id-less fields passed to 
`add_default_partition_spec`, the bound ids come out the same, but the recorded 
`AddSpec` has no `field-id` for the new field ([serde skips 
`None`](https://github.com/apache/iceberg-rust/blob/14f87b6ad33d4583913fb8c06aebed0bb80cd7e0/crates/iceberg/src/spec/partition.rs#L364-L373)),
 so a Java server would [number it from 
1000](https://github.com/apache/iceberg/blob/ea73769d120dc3819d8cfa2253b6dba4bb394886/api/src/main/java/org/apache/iceberg/PartitionSpec.java#L384-L396).
 The `set_field_ids` route keeps every id in `AddSpec` ([pinned 
here](https://github.com/apache/iceberg-rust/blob/14f87b6ad33d4583913fb8c06aebed0bb80cd7e0/crates/iceberg/src/spec/table_metadata_builder.rs#L4589-L4591))
 and errors at `i32::MAX`.



##########
crates/iceberg/src/spec/table_metadata_builder.rs:
##########
@@ -192,6 +193,86 @@ impl TableMetadataBuilder {
         )
     }
 
+    /// Replaces the table's schema, partition spec and sort order, leaving it 
with no
+    /// current snapshot. Backs `REPLACE TABLE`.
+    ///
+    /// The table keeps its uuid, properties and snapshots, so earlier 
snapshots stay readable.
+    /// Columns the table already has keep their field ids, so data written 
before the replacement
+    /// stays readable through the columns both schemas share; new columns get 
ids above
+    /// `last_column_id`, never a dropped column's id.
+    ///
+    /// Partition fields reuse the highest id an equivalent field has in any 
of the table's specs,
+    /// and other fields get ids above `last_partition_id`.
+    ///
+    /// `location` moves the table, `None` leaves it in place. `properties` 
are applied on top of
+    /// the existing ones. `format-version` upgrades the table without being 
persisted; other
+    /// reserved properties are ignored.
+    ///
+    /// # Errors
+    /// - The table is format version 1, which is not supported.
+    /// - `format-version` is invalid or would downgrade the table.
+    /// - The partition spec or sort order names a column missing from 
`schema`.
+    /// - `schema` takes the name of a partition field in one of the table's 
specs without being
+    ///   that field's source column.
+    pub fn build_replacement(

Review Comment:
   thanks, `pub(crate)` with the #3056 TODO works for me.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to