Make TextualFromNative output deterministic
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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