avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill de hOra <b...@dehora.net>
Subject schema defaults not reflected in generated objects (1.3.2)
Date Mon, 07 Jun 2010 20:53:27 GMT
Hi,

I.m wondering if I'm missing an incantation for 'compile 
schema/protocol' in Avro tools to handle defaults. Given this schema,

[[[
{
     "name": "avro.Message",
     "type": "record",
     "fields": [
         {
             "name": "foo",
             "type": "string",
             "default":"quux"
         },
         {
             "name": "bar",
             "type": "string"
         }
     ]

}
]]]

and running it through 'avro-tools-1.3.2.jar compile schema', I get this 
object

[[[
package avro;

@SuppressWarnings("all")
public class Message extends org.apache.avro.specific.SpecificRecordBase 
implements org.apache.avro.specific.SpecificRecord {
   public static final org.apache.avro.Schema SCHEMA$ = 
org.apache.avro.Schema.parse("{\"type\":\"record\",\"name\":\"Message\",\"namespace\":\"avro\",\"fields\":[{\"name\":\"foo\",\"type\":\"string\",\"default\":\"quux\"},{\"name\":\"bar\",\"type\":\"string\"}]}");
   public org.apache.avro.util.Utf8 foo = new Utf8("quux");
   public org.apache.avro.util.Utf8 bar;
   public org.apache.avro.Schema getSchema() { return SCHEMA$; }
   public java.lang.Object get(int field$) {
     switch (field$) {
     case 0: return foo;
     case 1: return bar;
     default: throw new org.apache.avro.AvroRuntimeException("Bad index");
     }
   }
   @SuppressWarnings(value="unchecked")
   public void put(int field$, java.lang.Object value$) {
     switch (field$) {
     case 0: foo = (org.apache.avro.util.Utf8)value$; break;
     case 1: bar = (org.apache.avro.util.Utf8)value$; break;
     default: throw new org.apache.avro.AvroRuntimeException("Bad index");
     }
   }
}
]]]

Should this line,

[[[
   public org.apache.avro.util.Utf8 foo;
]]]

be,

[[[
   public org.apache.avro.util.Utf8 foo
     = new org.apache.avro.util.Utf8("quux");
]]]

?

Fwiw, changing the object's 'foo' field above to have the default stops 
the IPC server from barfing with an NPE (@ 
org.apache.avro.io.BinaryEncoder.writeString(BinaryEncoder.java:133)) 
when a client creates a message object only sets 'bar', and then sends 
the Message to the server via .

Bill




Mime
View raw message