avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tejal Khot <tej...@yahoo-inc.com>
Subject How to use default in avro
Date Tue, 02 Nov 2010 01:53:03 GMT
Hi,

I am new to avro and I have been trying to resolve the AvroTypeException when using "default"
with the avro schema:
In the schema below, the service_wait field is a Boolean and I want to specify a default value.
However, I keep getting the exception below. What is the correct way to specify defaults?

org.apache.avro.AvroTypeException: Expected field name service_wait got select_branch
            at org.apache.avro.io.JsonDecoder.doAction(JsonDecoder.java:396)
            at org.apache.avro.io.parsing.Parser.advance(Parser.java:88)

Sample Schema:

{
  "type": "record",
  "name": "TestRequest",
  "fields" : [
    {"name": "ver", "type": "string"},
    {"name": "trace_id", "type": "int"},
    {"name": "error_at", "type": "string"},
    {"name": "exception_at", "type": "string"},
    {"name": "bytes", "type": "bytes"},
    {"name": "need_trace_buffer", "type": "boolean"},
    {"name": "service_wait", "type": "boolean", "default" :"true"},
    {"name": "select_branch", "type": "string"},
    {
      "name": "serviceData",
      "type": {
        "type": "array",
        "items":  {
          "type": "record",
          "name": "ServiceData",
          "fields" : [
            {"name": "nm", "type": "string"},
            {"name": "latency", "type": "int"},
            {"name": "req", "type": "bytes"}
          ]
        }
      }
    }


  ]
}

Sample data file is as below:
{
    "ver" : "1.0",
    "trace_id" : 3000301,
    "error_at" : "",
    "exception_at" : "",
    "bytes" : "1234567" ,
    "need_trace_buffer" : false,
    "service_wait" : true,
    "select_branch" : "",
    "serviceData" : [
        {
            "nm" : "HttpService3",
            "latency" : 5,
            "req" : "/"
        }
    ]
}



The exception:

org.apache.avro.AvroTypeException: Expected field name service_wait got select_branch
            at org.apache.avro.io.JsonDecoder.doAction(JsonDecoder.java:396)
            at org.apache.avro.io.parsing.Parser.advance(Parser.java:88)
            at org.apache.avro.io.JsonDecoder.advance(JsonDecoder.java:67)
            at org.apache.avro.io.JsonDecoder.readBoolean(JsonDecoder.java:96)
            at org.apache.avro.io.ValidatingDecoder.readBoolean(ValidatingDecoder.java:63)
            at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:92)
            at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:108)
            at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:80)
            at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:71)
            at com.yahoo.dataintensive.streaming.streaming2transporter.AvroSchemaTest1.main(AvroSchemaTest1.java:32)


Thanks,
Tejal

Mime
View raw message