goavro
goavro copied to clipboard
[Bug] Can't write OCR when schema have union type
There is an issue when writing OCR with a schema containing union type.
I've changed your example like this:
avroSchema := `
{
"type": "record",
"name": "test_schema",
"fields": [
{
"name": "time",
"type": "long"
},
{
"name": "customer",
"type": ["null", "string"],
"default": null
}
]
}`
// Writing OCF data
var ocfFileContents bytes.Buffer
writer, err := goavro.NewOCFWriter(goavro.OCFConfig{
W: &ocfFileContents,
Schema: avroSchema,
})
if err != nil {
fmt.Println(err)
}
err = writer.Append([]map[string]interface{}{
{
"time": 1617104831727,
"customer": "customer1",
},
{
"time": 1717104831727,
"customer": "customer2",
},
})
fmt.Println("ocfFileContents", ocfFileContents.String())
The output doesn't contains data.
But if I set nil
for customer the data are written.
err = writer.Append([]map[string]interface{}{
{
"time": 1617104831727,
"customer": nil,
},
{
"time": 1717104831727,
"customer": nil,
},
})