func (*OCFWriter) Append is not appending my data to the avro file
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.1k
- Forks
- 232
- PR merge metrics
- No merged PRs in 30d
Description
[input.json](https://github.com/linkedin/goavro/files/12929937/input.json)
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"github.com/linkedin/goavro/v2"
)
func main() {
jsonFile, err := os.Open("input.json")
if err != nil {
fmt.Println(err)
}
defer jsonFile.Close()
// read our opened xmlFile as a byte array.
byteValue, _ := ioutil.ReadAll(jsonFile)
// we initialize our Users array
var result map[string]interface{}
// we unmarshal our byteArray which contains our resultset
json.Unmarshal(byteValue, &result)
finalresult := []map[string]interface{}{}
appendresult := []map[string]any{}
for k, v := range result {
m1 := make(map[string]interface{})
m2 := make(map[string]any)
m1["name"] = k
switch v.(type) {
case string:
m1["type"] = "string"
m2[k] = v
appendresult = append(appendresult, m2)
case float64:
m1["type"] = "long"
m2[k] = v
appendresult = append(appendresult, m2)
default:
m1["type"] = "null"
m2[k] = result[k]
appendresult = append(appendresult, m2)
}
finalresult = append(finalresult, m1)
}
jsonString, _ := json.Marshal(finalresult)
var fields []Field
json.Unmarshal(jsonString, &fields)
type recordschema struct {
Name string `json:"name"`
Type string `json:"type"`
Fields []Field `json:"fields"`
}
group := recordschema{
Name: "record",
Type: "record",
Fields: fields,
}
b, err := json.Marshal(group)
codec, err := goavro.NewCodec(string(b))
if err != nil {
fmt.Println(err)
}
var ocfFileContents bytes.Buffer
writer, err := goavro.NewOCFWriter(goavro.OCFConfig{
W: &ocfFileContents,
Schema: codec.Schema(),
})
if err != nil {
fmt.Println(err)
}
err = writer.Append(appendresult)
fmt.Println(ocfFileContents.String())
file, err := os.Create("output16.avro")
if err != nil {
panic(err)
}
defer file.Close()
// Write the Avro binary data to the file
_, err = file.Write(ocfFileContents.Bytes())
if err != nil {
panic(err)
}
}
type Field struct {
Name string `json:"name"`
Type string `json:"type"`
}

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 by reproducing the supplied Go program with input.json and inspect the error returned by writer.Append, along with the generated output16.avro contents. Compare the records passed to Append with the codec schema; done means the resulting Avro file contains the input records and can be read back successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100