-
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
Decoding of map[string]any behavior changed #386
Comments
Yes, this was intended. Map mode record decode In 1.18, generic decoding and struct decoding were split, generic decoding being handled by Side Note: It is a little odd that you mix generic and struct en/decoding. As this is schemaed, I would expect it all to be structs, as this is has higher performance. Generic decoding is more difficult for the decoder, and has a heavy performance penalty. |
Thanks for the quick info! I appreciate it. What do you mean by mixing genreric and struct? The partition struct above gets populated at runtime with potentially arbitrary types, so I needed a way to encode those types. I template the avro spec based off of the types that are found in the map. Edit: I tried using |
Data here is a strict that maps to the
That makes sense then. Just through I would point it out. |
Hey @thorfour Did you find a work around for this? Is there anything better then iterating through the decoded results and converting every value from I also like not having to hardcode structs into my application. The schema is already laid out in Schema Registry so I'd rather control it dynamically from there, then having to coordinate a redeploy on every minor schema change. |
@TheGreatAbyss unfortunately no I didn't. My solution was to pin my version of this library at |
I'll probably do the same for now. Thanks |
Thank you for this library, it's amazing. I'm not even going to pretend I understand the bowels of everything that it's doing, but following along the decoder it looks like the actual interface value is extracted all the way up until this line: Line 115 in 4aff30f
Thanks again, and apologies if my question is not informed. |
|
Wait. It is possible I got something wrong in my explanation. I need to check this. |
Thank You!!! FWIW, In the old version this was the code that worked:
|
The current version still calls genericDecode which does the same thing as the old version:
But once that object is returned, instead of it being set, you now call Again sorry if I'm over my head but just trying to help make this more seamless for users. |
The actual thing we are looking at is this: https://github.com/hamba/avro/blob/v2.24.0/codec_record.go#L278 It is possible it is actually a bug. I apologise if I missed this. Just need to double check everything before I actually call it a bug. |
I never get to that code block in my tests which have a simple schema of something like:
] I simple encode a test map[string]any and then decode it back into another map[string]any Regardless, thank you for investigating!! |
Here is the comparison I am making, based on the original schema and example:
in 2.24 the same result is:
So in effect, the change was to aline all the decodings to be the same. So I would not class this as a bug. |
The flip side of the argument is that it is an |
I think the original example is adding some confusion here being a record with a nested record. Now I understand why you were looking at the block of code. If you just have a simple schema without nested records the old versions simply decoded into a Example schema:
Since I stick to flat simple schemas, as far as I'm concerned there is no consistency issues. It went from I can work on posting a complete example. My tests have a bunch of underlying mocks and types so it's not easy to quickly copy and paste |
@redaLaanait You want to weigh in here? I don't really know which handling is "technically" correct here. Handling this like |
Here's a simple example. This test passes in <= 19 but fails now:
IMHO - Seems inconsistent to not be able to decode into exactly the same object you encoded in the first place. |
@TheGreatAbyss So the discussion is about how Unions are handled in a Record represented by a
We need to first check that nested schemas do not break in Option 1, and figure out the "correct" way forward. |
Seeing as this changed as part of an optimisation commit, I am tending towards this being a bug. |
@TheGreatAbyss Could you test the above PR to see that it sorts your issue, for confirmation? |
Yes it passed!!
Thank You! |
Oh wow this is great news! |
@thorfour Apologies for not digging deeper the first time. I will see if @redaLaanait has time to look and double check, as he did the original work, so could take a short while, but the more I look at it, the more it seems that I made a mistake here. |
Thank You for such a quick turnaround! |
I noticed that the behavior of decoding a complex type of
map[string]any
changed between v2.19.0 and v2.20.0 and was curious if that was intended to change how avro parses this type of struct?The test below encodes and decodes a struct that has a
map[sting]any
element.If I decode with v2.19.0 I get an output of
{map[a:1 b:2]}
which is what I was expectingas that's the map type I encoded. But when upgrading to v2.20.0 or higher I get{map[a:map[int:1] b:map[int:2]]}
Am I doing something wrong or is this working as intended?
The text was updated successfully, but these errors were encountered: