linkedin / linkedin/goavro

Make TextualFromNative output deterministic

Open
#222 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
1.1k
Forks
232
PR merge metrics
No merged PRs in 30d

Description

TextualFromNative output is not deterministic due to the underlying map type used for the data struct.
Ideally the method should be deterministic similarly to what the [json.Marshal](https://golang.org/pkg/encoding/json/#Marshal) already does by sorting the map keys.

Current behaviour:
```
codec, err := goavro.NewCodec(`
{
"type": "record",
"name": "Schema",
"fields" : [
{"name": "first", "type": "string"},
{"name": "second", "type": "string"}
]
}`)
if err != nil {
fmt.Println(err)
}

val := map[string]interface{}{"first":"foo", "second":"bar"}
for i:=0; i<20;i++ {
b, _ := codec.TextualFromNative(nil, val)
fmt.Println(string(b))
}
```

Result:
```
{"first":"foo","second":"bar"}
{"second":"bar","first":"foo"}
{"first":"foo","second":"bar"}
{"second":"bar","first":"foo"}
{"first":"foo","second":"bar"}
{"first":"foo","second":"bar"}
{"first":"foo","second":"bar"}
{"first":"foo","second":"bar"}
{"first":"foo","second":"bar"}
{"first":"foo","second":"bar"}
{"second":"bar","first":"foo"}
{"first":"foo","second":"bar"}
{"second":"bar","first":"foo"}
{"first":"foo","second":"bar"}
{"first":"foo","second":"bar"}
{"first":"foo","second":"bar"}
{"first":"foo","second":"bar"}
{"first":"foo","second":"bar"}
{"first":"foo","second":"bar"}
{"first":"foo","second":"bar"}
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at codec.TextualFromNative, the entry point shown in the issue, and trace how map-backed record fields are emitted. Add a regression test that calls the method repeatedly with the sample value and verifies stable, key-sorted output; done means the output is deterministic like json.Marshal.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.