zeroshade commented on code in PR #1822:
URL: https://github.com/apache/iceberg-go/pull/1822#discussion_r3807499859
##########
table/updates.go:
##########
@@ -158,17 +154,45 @@ func (u *Updates) UnmarshalJSON(data []byte) error {
updates = make(Updates, 0, len(rawUpdates))
}
for _, raw := range rawUpdates {
- var baseWire struct {
- Action *string `json:"action"`
- }
- if err := json.Unmarshal(raw, &baseWire); err != nil {
+ var object map[string]json.RawMessage
+ if err := json.Unmarshal(raw, &object); err != nil {
return err
}
- if baseWire.Action == nil {
- return fmt.Errorf("%w: update requires field %q",
iceberg.ErrInvalidArgument, "action")
+
+ actionValue, exactAction := object["action"]
+ actionFieldCount := 0
+ caseVariantAction := false
+ for field := range object {
+ if strings.EqualFold(field, "action") {
+ actionFieldCount++
+ if field != "action" {
+ caseVariantAction = true
+ }
+ }
}
- base := baseUpdate{ActionName: *baseWire.Action}
+ var action string
+ if exactAction && !caseVariantAction {
Review Comment:
**Major: exact duplicate `action` keys can still erase an `encoding/json`
type error.** By this fast path, decoding into `object` has already collapsed
duplicate exact keys. For
`[{"action":123,"action":"set-properties","updated":{"k":"v"}}]`, the merge
base returns `*json.UnmarshalTypeError`, but the current code selects the final
string, legacy-normalizes and re-marshals the map, then succeeds because the
earlier invalid number is gone. Please preserve the discriminator's original
decode error before any map round-trip and add this payload as a regression
test.
--
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]