riverandeye opened a new issue, #2828:
URL: https://github.com/apache/iceberg-go/issues/2828

   ### Summary
   
   `UpdateSchema.DeleteColumn` drops a column that is the source of a field in 
the table's default partition spec, and the commit succeeds. The written 
metadata has a default spec that references a column the current schema no 
longer has. Java rejects this change and fails to load the resulting metadata.
   
   The same drop of a sort order source column is already rejected when the 
metadata is built.
   
   ### Current behavior
   
   Table partitioned by `identity(age)`, then `age` is dropped.
   
   ```go
   txn := tbl.NewTransaction()
   err := txn.UpdateSchema(true, false).DeleteColumn([]string{"age"}).Commit() 
// nil
   staged, err := txn.StagedTable()                                           
// nil
   ```
   
   The staged metadata keeps the spec `[ 1000: age: identity(3) ]` with a 
current schema that has no field 3. Catalogs that build metadata locally write 
it as is.
   
   `MetadataBuilder.Build` checks the default sort order against the current 
schema, but not the default partition spec.
   
   
[`table/metadata.go#L3040-L3052`](https://github.com/apache/iceberg-go/blob/43e3820a05ef2d185f231b1605051d6f1b1547c5/table/metadata.go#L3040-L3052)
   
   ```go
   func (c *commonMetadata) checkSortOrders() error {
        ...
                        if err := o.CheckCompatibility(c.CurrentSchema()); err 
!= nil {
                                return fmt.Errorf("%w: default sort order %d is 
not compatible with current schema: %w", ...)
   ```
   
   
[`checkPartitionSpecs`](https://github.com/apache/iceberg-go/blob/43e3820a05ef2d185f231b1605051d6f1b1547c5/table/metadata.go#L3015-L3038)
 only checks for duplicate spec IDs and that the default spec exists.
   
   ### Expected behavior
   
   The change is rejected, as in Java. Java checks the default spec and the 
default sort order against the current schema every time it builds metadata.
   
   
[`TableMetadata.java#L1572-L1574`](https://github.com/apache/iceberg/blob/2e12b22aea8e43af1d3bc1559decc6bbe2e92ac0/core/src/main/java/org/apache/iceberg/TableMetadata.java#L1572-L1574)
   
   ```java
         Schema schema = schemasById.get(currentSchemaId);
         PartitionSpec.checkCompatibility(specsById.get(defaultSpecId), schema);
         SortOrder.checkCompatibility(sortOrdersById.get(defaultSortOrderId), 
schema);
   ```
   
   The commit fails with `Cannot find source column for partition field: 1000: 
age: identity(3)` 
([`PartitionSpec.java#L664-L665`](https://github.com/apache/iceberg/blob/2e12b22aea8e43af1d3bc1559decc6bbe2e92ac0/api/src/main/java/org/apache/iceberg/PartitionSpec.java#L664-L665)).
 The parser binds the default spec with the same check, so Java cannot load 
metadata that Go wrote this way 
([`TableMetadataParser.java#L417-L420`](https://github.com/apache/iceberg/blob/2e12b22aea8e43af1d3bc1559decc6bbe2e92ac0/core/src/main/java/org/apache/iceberg/TableMetadataParser.java#L417-L420)).
   
   Java does not check older specs, and it skips `void` fields. A column used 
only by a historical spec, or by a v1 field already replaced with `void`, can 
still be dropped. #1191 and #1205 cover reading such tables.
   
   ### Proposed change
   
   In `MetadataBuilder.Build`, check that every non-void field of the default 
partition spec has its source columns in the current schema, next to the 
existing sort order check. Leave the read path unchanged, so tables that were 
already written this way can still be loaded and scanned.
   


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