Revanth14 commented on code in PR #2372:
URL: https://github.com/apache/iceberg-go/pull/2372#discussion_r4461059420
##########
defaults.go:
##########
@@ -49,3 +53,108 @@ func CloneDefaultValue(value any) any {
return value
}
}
+
+// hexDefault returns the hex single-value form of a binary or fixed default
+// given as bytes. It reports false for any other type or value, including a
+// default that is already a string.
+func hexDefault(typ Type, value any) (string, bool) {
+ switch typ.(type) {
+ case BinaryType, FixedType:
+ switch value := value.(type) {
+ case []byte:
+ return internal.EncodeDefaultBytes(value), true
+ case BinaryLiteral:
+ return internal.EncodeDefaultBytes(value), true
+ case FixedLiteral:
+ return internal.EncodeDefaultBytes(value), true
+ }
+ }
+
+ return "", false
+}
+
+// normalizeDefaults stores binary and fixed defaults in their hex single-value
+// form, the same form metadata JSON decodes to, so a schema holds no byte
Review Comment:
Narrowed both: the `normalizeDefaults` comment and the
`NewSchemaWithIdentifiers` doc now say only a binary or fixed field's own
default is converted, and a `[]byte` inside a `[]any` or `map[string]any`
default is left as is.
##########
website/src/releases.md:
##########
@@ -42,6 +42,7 @@ Per-release notes (highlights, breaking changes,
contributors) are published on
### Unreleased compatibility notes
+- **Schemas store binary and fixed defaults as hex strings.** `NewSchema`,
`NewSchemaWithIdentifiers` and `NewSchemaFromJSONFields` convert `[]byte`,
`BinaryLiteral` and `FixedLiteral` defaults on binary and fixed fields, at any
depth, to the hex string used in metadata JSON, so a field read back from a
schema holds a `string` such as `"0aff"`. Code that type-asserts these defaults
to `[]byte` must decode the string instead, for example with
`hex.DecodeString`. A schema built in process now equals the same schema read
from metadata. The fields and types passed in are not modified.
Review Comment:
Replaced `NewSchemaFromJSONFields` with `UpdateSchema.AddColumn` (through
`Apply()`). The equality claim now says lowercase hex and notes that `Equals`
is case-sensitive while Java writes uppercase, linking apache/iceberg#18352.
--
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]