avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Siva <sbhavan...@gmail.com>
Subject fromJson is failing with null as uniontype
Date Thu, 18 Feb 2016 00:21:59 GMT
Hi Everyone,

I m new to avro, running into issues if a type is combined with "null",
like ["null","int"] or ["null", "string"].

I have a schema like below

{
   "type":"record","namespace":"tutorialspoint",
  "name":"empdetails","fields":[  {
         "name":"experience",
         "type":["null","string"],"default":null
      },
      {  "name":"age", "type":"int" }
   ]
}

Below is the json dataset.

{"experience" : "da",  "age": 50}

java -jar avro-tools-1.7.7.jar fromjson --schema-file test.avsc test.json >
test.avro

If I have "null" value in "experience" column it goes though, but if it has
some string it is giving below error. Similar error with int types as well
(VALUE_NUMBER_INT).

Exception in thread "main" org.apache.avro.AvroTypeException: Expected
start-union. Got VALUE_STRING
        at org.apache.avro.io.JsonDecoder.error(JsonDecoder.java:697)
        at org.apache.avro.io.JsonDecoder.readIndex(JsonDecoder.java:441)
        at
org.apache.avro.io.ResolvingDecoder.doAction(ResolvingDecoder.java:290)
        at org.apache.avro.io.parsing.Parser.advance(Parser.java:88)

I have columns with strings or nulls in json, is there a work around to
this error without changing the json data?

Thanks in advance.

Thanks,
Sivakumar Bhavanari.

Mime
View raw message