-
Notifications
You must be signed in to change notification settings - Fork 125
Closed
Description
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?
func Test_Avro(t *testing.T) {
schema := `{
"type": "record",
"name": "data",
"fields": [
{ "name": "partition", "type": {"type": "record", "name": "test1", "fields": [
{ "name": "a", "type": ["null", "int"]},
{ "name": "b", "type": ["null", "int"]}
]}}
]
}`
avro.MustParse(schema)
type Data struct {
Partition map[string]any `avro:"partition"`
}
w := &bytes.Buffer{}
enc, err := ocf.NewEncoder(
schema,
w,
ocf.WithMetadata(map[string][]byte{
"avro.codec": []byte("deflate"),
}),
ocf.WithCodec(ocf.Deflate),
)
require.NoError(t, err)
require.NoError(t, enc.Encode(Data{
Partition: map[string]any{
"a": 1,
"b": 2,
},
}))
require.NoError(t, enc.Close())
// Read back the file
d, err := ocf.NewDecoder(bytes.NewReader(w.Bytes()))
require.NoError(t, err)
for d.HasNext() {
var data Data
require.NoError(t, d.Decode(&data))
fmt.Println(data)
}
}Metadata
Metadata
Assignees
Labels
No labels