ShivamSharma43 opened a new issue, #2695:
URL: https://github.com/apache/iceberg-go/issues/2695
### Apache Iceberg version
main (development)
### Please describe the bug 🐞
A decimal column default is lost when table metadata is written as JSON.
`AddColumn` stores the default literal's `Any()` value, which for a decimal is
an `iceberg.Decimal`. `NestedField.MarshalJSON` passes it through
`defaultValueToJSON` unchanged, and `iceberg.Decimal` has no JSON encoding of
its own. Its `decimal128.Num` has no exported fields, so the default is written
as `{"Val":{},"Scale":2}` and the value is gone.
Reproduced on main (58f9565):
```go
typ := iceberg.MustDecimalTypeOf(9, 2)
lit, _ := iceberg.NewLiteral("14.20").To(typ)
field := iceberg.NestedField{ID: 1, Name: "price", Type: typ,
InitialDefault: lit.Any(), WriteDefault: lit.Any()}
out, _ := json.Marshal(field)
fmt.Println(string(out))
```
Output:
```
{"id":1,"name":"price","type":"decimal(9,
2)","required":false,"initial-default":{"Val":{},"Scale":2},"write-default":{"Val":{},"Scale":2}}
```
Expected: `"initial-default":"14.20","write-default":"14.20"`. The spec's
[JSON single-value
serialization](https://iceberg.apache.org/spec/#json-single-value-serialization)
writes `decimal(P, S)` as a string such as `"14.20"`, and so does Java's
[`SingleValueParser`](https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/SingleValueParser.java).
End to end: on a v3 table, after `AddColumn([]string{"price"}, decimal(9,
2), "", false, <14.20>)` and reloading the metadata JSON the way a catalog
does, the field's defaults are no longer `"14.20"`, and scanning a data file
written before the column existed fails instead of returning `14.20` for
`price`.
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]