Not in union ["null","int"] Avro Format org.apache.avro.UnresolvedUnionException

5k Views Asked by At

I have a java program which writes data from Oracle db in avro format. I am getting this exception on a date column while writing

org.apache.avro.file.DataFileWriter$AppendWriteException: org.apache.avro.UnresolvedUnionException: Not in union ["null","int"]: 2020-04-01

I am using avro 1.9.2 version. Below is the schema :

{
  "type": "record",
  "name": "some",
  "doc": "SOME",
  "namespace": "some.avro",
  "fields": [
    {
      "name": "SOME_DATE",
      "type": [
        "null",
        "int"
      ],
      "logicalType": "date",
      "default": null
    }
..

  ]
}

When I use below schema with string it works fine.

{"name":"SOME_DATE","type": ["null","string"]}
1

There are 1 best solutions below

0
On

Your schema should look like this:

{
  "type": "record",
  "name": "some",
  "doc": "SOME",
  "namespace": "some.avro",
  "fields": [
    {
      "name": "SOME_DATE",
      "type": [
         "null",
         { "type": "int", "logicalType": "date" }
      ],
      "default": null
    }
  ..

  ]
}

But then you'll probably get a nasty problem with conversion for union types with default values and logical types inside that union. ))