Shruthirdy opened a new pull request, #2774:
URL: https://github.com/apache/iceberg-go/pull/2774

   Closes #2754.
   
   When `UpdateColumn` or `UnionByNameWith` promoted a column's type, its 
`initial-default` and `write-default` kept the old type. After int→long, the 
schema returned by `Apply()` had `int32` defaults on a `long` column; only 
reloading the metadata JSON gave `int64`. Java converts both defaults: the 
`NestedField` constructor runs `castDefault` → `defaultValue.to(type)` 
(`Types.java:891-903`).
   
   Before:
   ```
   type=long initial=int32 write=int32
   ```
   
   After:
   ```
   type=long initial=int64 write=int64
   ```
   
   ### Change
   
   - A promotion now converts both defaults to the new type:
     - int→long: `int32(1)` becomes `int64(1)`.
     - float→double: `float32(1.1)` becomes `float64(float32(1.1))`, written as 
`1.100000023841858`. That's the value existing float data reads as after the 
promotion, and what Java writes.
     - Decimal widening: the default is unchanged, since the value is the same.
   - A write default set in the same `UpdateColumn` still replaces the 
converted one.
   - Columns added in the same update are converted too, through `u.adds` 
(#2714).
   
   ### Approach
   
   The conversion happens in `updateColumn`, where the type is set, so existing 
and just-added columns share one path. The Apply visitor then takes 
`InitialDefault` from the pending update. Converting in the visitor would miss 
added columns, which it appends as they are.
   
   Only promotions convert. Go's `allowIncompatibleChanges` also allows type 
changes such as int→string or long→int, which Java rejects outright. Converting 
those would clamp values (2^40 → int32 max), so their defaults are left as they 
are.
   
   The two `cannot convert …-default` errors can't be reached with today's 
promotions. They're kept so that a future promotion that can't convert a 
default returns an error instead of leaving it stale.
   
   ### Unchanged
   
   The allowed type changes, columns without defaults, and non-promotion 
changes under `allowIncompatibleChanges`.
   
   ### Testing
   
   `TestUpdateColumnPromotionConvertsDefaults` covers:
   - each promotion
   - a nested column and a just-added column
   - a later update keeping the converted defaults
   - a new write default in the same update
   - `UnionByNameWith`
   - incompatible changes and narrowing keeping their defaults
   - the committed in-memory schema and a metadata JSON round trip
   
   ### Follow-ups
   
   - With `allowIncompatibleChanges`, a non-promotion type change keeps a 
default
     of the old type. For example, int→string leaves the integer `5` as the
     default of a string column, and `Commit` succeeds. Possible fixes:
     1. Reject non-promotion type changes even with `allowIncompatibleChanges`,
        as Java does (`SchemaUpdate.java:284-289`). This breaks callers that 
rely
        on the flag for type changes.
     2. Keep allowing the type change, but reject defaults that don't fit the 
new
        type, as `validateDefaultValue` does elsewhere.
     3. Keep allowing the type change and clear the defaults. This drops them
        silently.
   
     I'll open a separate issue once there's agreement on the direction.
   
   
   **Happy to change the approach if maintainers prefer a different one.**
   


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