-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
union: add option to decoding into map with namespace #494
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am trying to understand the desired behaviour. It seems in most cases you are looking for the generic behaviour, but in specific cases you want it to return say a map[string]int
which is not generic?
I basically want it to be in this format: https://avro.apache.org/docs/1.11.1/specification/#json-encoding Which means a schema like:
Is decoded, then marshaled into JSON to be:
Where the current main branch only supports decoding this as:
Which means that if you Unmarshal an avro type using |
Let me remove the |
This part of it I would consider a bug, except in the case that a union is directly decoded into an |
Well it should happen for "top level" types too (not part of a larger map[string]any or []any, otherwise it wouldn't match the spec. FWIW an older version of the library actually did this right (we were on 2.22 and tried updating to 2.27 which broke our tests). It's possible to get the "non map" version of the union via post processing because we have an option to toggle between union encoding mode, our current logic is here: |
This patch adds an option to allow decoding generic data into a `map` type so that the native decoded output matches the avro spec for union JSON encoding. This is useful when handling generic/dynamic avro data and allows us to drop a dependency on linkedin/goavro.
I updated the tests to drop the |
Also with respect to this being an option or not, it seems some people don't want the spec JSON encoding: #386 This is why I assumed an option would be desired. |
Honestly, at some point I need to cut a new major to get behaviour to be defined at a point, but have not had the time for such a big push. The old behaviour is still available in As for this PR, you are likely correct with adding the option, I had obviously forgotten the old issues. I think the last remaining issue is that a generic decode can return something like a |
nice! thank you for this, this helps us upgrade and I believe is faster too (less reflection): redpanda-data/connect#3154
I am happy to do this, however I've realized if you pass in a struct type to decode and supply this option, then there will be panics from trying to assign a map to a struct type... How would you feel about just closing this PR until you have time for the new major and getting the behavior here well defined and buttoned up? I'm happy with the reader workaround for now. |
That is fine by me. Appreciate the effort. |
This patch adds an option to allow decoding generic data into a
map
type so that the native decoded output matches the avro spec for union
JSON encoding. This is useful when handling generic/dynamic avro data and
allows us to drop a dependency on linkedin/goavro.