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

   No default value could be set on a `timestamptz` or `timestamptz_ns` column 
through `UpdateSchema` (see #2725 for the reproduction). iceberg-go has no 
zoned timestamp literal: `TimestampLiteral` and `TimestampNsLiteral` report 
`timestamp` and `timestamp_ns`, and they are what `iceberg.NewLiteral` returns 
for `iceberg.Timestamp` and `iceberg.TimestampNano`. The default checks 
compared that type with the column type exactly, so:
   
   - `AddColumn` failed with `default value type mismatch: timestamp != 
timestamptz`.
   - `UpdateColumn` with a `WriteDefault`, and `UnionByNameWith` with a default 
on a timestamptz field, failed in `validateDefaultValue` with `value of type 
timestamp does not match column type timestamptz`.
   
   ### Fix
   
   A new `defaultTypeMatches` helper in `table/update_schema.go`, used by both 
checks, treats a `timestamp` literal as matching a `timestamptz` column and a 
`timestamp_ns` literal as matching a `timestamptz_ns` column. Every other pair 
still has to match exactly, so a `timestamp_ns` literal for a `timestamptz` 
column is still rejected. The stored value doesn't change 
(`Timestamp`/`TimestampNano`), and `defaultToScalar` already handles it for 
both zoned and unzoned columns.
   
   Java reference: `NestedField` casts a default with 
[`defaultValue.to(type)`](https://github.com/apache/iceberg/blob/cfc80db65bff096bc52e580d1fee9f3a78febb34/api/src/main/java/org/apache/iceberg/types/Types.java#L895-L907),
 and 
[`TimestampLiteral.to`](https://github.com/apache/iceberg/blob/cfc80db65bff096bc52e580d1fee9f3a78febb34/api/src/main/java/org/apache/iceberg/expressions/Literals.java#L445-L456)
 returns itself for any `TIMESTAMP` type, with or without zone.
   
   This doesn't overlap with #2717, which changes how temporal defaults are 
written to and read from metadata JSON. The two branches merge cleanly.
   
   ### Testing
   
   - `TestTimestampTzDefaults` (`table/update_schema_test.go`) sets 
`timestamptz` and `timestamptz_ns` defaults on a v3 table through `AddColumn`, 
`UpdateColumn` and `UnionByNameWith`, and checks a `timestamp_ns` literal is 
still rejected for a `timestamptz` column. The first three subtests fail on 
main with the errors above and pass with the fix.
   - `go vet ./table/` is clean. `go test ./table/` passes except for 31 tests 
that fail the same way on unmodified main on Windows, where the temp 
directory's drive letter ends up in a file URL or as a warehouse scheme (for 
example `TestComputeNDVs*`, `TestVariantExtract*`, `TestTable`, 
`TestWriteMapType`). The list of failing tests is identical with and without 
this change, and none of them involve column defaults.
   
   Closes #2725
   
   This PR was prepared with AI assistance (Claude Code).
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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