Skip to content

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

Description

@florentsorel

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions