laskoviymishka commented on code in PR #2696:
URL: https://github.com/apache/iceberg-go/pull/2696#discussion_r4678730581
##########
types.go:
##########
@@ -372,6 +372,12 @@ func defaultValueToJSON(typ Type, value any) any {
if encoded, ok := hexDefault(typ, value); ok {
return encoded
}
+ // Decimal has no JSON encoding of its own, and its decimal128 value
has no
+ // exported fields, so it would be written as {"Val":{},"Scale":2} and
lose
+ // the value. Write the spec's single-value form, a string such as
"14.20".
+ if d, ok := value.(Decimal); ok {
+ return d.String()
Review Comment:
Should `validateDefaultValue` also check the decimal scale against the
column? `AddColumn` rejects a scale-3 literal on `decimal(9, 2)` through
`Type().Equals`, but `UpdateColumn` accepts it as a `WriteDefault`
([validateDefaultValue](https://github.com/apache/iceberg-go/blob/cd338dc041b6b92f906354bd6fc826f00059b9d7/table/update_schema.go#L1014-L1037)),
and this branch then writes `"write-default":"14.200"`. Java's
`SingleValueParser` rejects that ([scale
check](https://github.com/apache/iceberg/blob/c44bd8e7c183cf92339939f2aff5ca2aa2a0fd3d/core/src/main/java/org/apache/iceberg/SingleValueParser.java#L87-L101))
and our reader rounds it silently. On `main` the value was lost anyway. A
scale check plus an `UpdateColumn` write-default test would cover it.
--
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]