ShivamSharma43 opened a new issue, #2725:
URL: https://github.com/apache/iceberg-go/issues/2725
### Apache Iceberg version
main (development)
### Please describe the bug 🐞
No default value can be set on a `timestamptz` or `timestamptz_ns` column
through `UpdateSchema`.
iceberg-go has no zoned timestamp literal. `TimestampLiteral` and
`TimestampNsLiteral` report `timestamp` and `timestamp_ns`, and they are what
`iceberg.NewLiteral` returns for an `iceberg.Timestamp` or
`iceberg.TimestampNano`. The default checks in `table/update_schema.go` compare
the literal's type with the column type exactly, so they reject every
timestamptz default:
- `AddColumn` (`defaultValue.Type().Equals(t)`)
- `UpdateColumn` with a `WriteDefault`, and `UnionByNameWith` with an
`InitialDefault`/`WriteDefault`, both through `validateDefaultValue`
(`nativeDefaultLiteral(v)` then `lit.Type().Equals(t)`)
Reproduced on main (b9a9bd9), on a v3 table:
```go
ts := iceberg.Timestamp(1510871468123456)
_, err := txn.UpdateSchema(true, false).
AddColumn([]string{"created"}, iceberg.PrimitiveTypes.TimestampTz, "",
false, iceberg.NewLiteral(ts)).
Apply()
// default value type mismatch: timestamp != timestamptz
_, err = txn.UpdateSchema(true, false).
UpdateColumn([]string{"updated"}, table.ColumnUpdate{ // an existing
timestamptz column
WriteDefault: iceberg.Optional[iceberg.Literal]{Valid: true,
Val: iceberg.NewLiteral(ts)},
}).
Apply()
// invalid write-default for updated: value of type timestamp does not match
column type timestamptz
```
The same happens with an `iceberg.TimestampNano` default on a
`timestamptz_ns` column. A `timestamp` column works.
Java accepts these defaults: `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.
I'd like to work on this. I have a fix and tests ready.
--
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]