goavro icon indicating copy to clipboard operation
goavro copied to clipboard

[Bug] Can't write OCR when schema have union type

Open florentsorel opened this issue 10 months ago • 0 comments

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. image

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,
	},
})

image

florentsorel avatar Apr 17 '24 12:04 florentsorel