avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@apache.org>
Subject Re: AvroTypeException thrown with version change on optional record
Date Wed, 07 Dec 2011 22:47:58 GMT
I think you have the parameters reversed to SpecificDatumWriter and
SpecificDatumReader.  If v2 is the new version, then you should
construct a SpecificDatumWriter<v1.Response> to write the old version
and a SpecificDatumReader<v2.Response> to read the new one.  The
parameters to SpecificDatumReader's constructor are old-then-new, so
you'll need to reverse those too.

Doug

On 12/07/2011 02:40 PM, Francois Forster wrote:
> It seems to work when I do the reverse (add @aliases(["v2.Result"]) to the v1 schema),
but that's not useful when dealing with versioning.
> 
> Francois.
> 
> -----Original Message-----
> From: Francois Forster [mailto:francois.forster@bazaarvoice.com] 
> Sent: Wednesday, December 07, 2011 4:34 PM
> To: user@avro.apache.org
> Subject: RE: AvroTypeException thrown with version change on optional record
> 
> Interesting. I tried it but get:
> 
> Exception in thread "main" org.apache.avro.AvroTypeException: Found {
>   "type" : "record",
>   "name" : "Review",
>   "namespace" : "v2",
>   "fields" : [ {
>     "name" : "id",
>     "type" : "string"
>   }, {
>     "name" : "text",
>     "type" : "string"
>   }, {
>     "name" : "isRecommended",
>     "type" : "boolean"
>   } ],
>   "aliases" : [ "v1.Review" ]
> }, expecting [ "null", {
>   "type" : "record",
>   "name" : "Review",
>   "namespace" : "v1",
>   "fields" : [ {
>     "name" : "id",
>     "type" : "string"
>   }, {
>     "name" : "text",
>     "type" : "string"
>   }, {
>     "name" : "isRecommended",
>     "type" : "boolean"
>   } ]
> } ]
> 
> 
> -----Original Message-----
> From: Doug Cutting [mailto:cutting@apache.org] 
> Sent: Wednesday, December 07, 2011 4:15 PM
> To: user@avro.apache.org
> Subject: Re: AvroTypeException thrown with version change on optional record
> 
> On 12/07/2011 01:41 PM, Francois Forster wrote:
>> Actually, it happens even if I don't add isFeatured. Is there something
>> incompatible due to the different namespace?
> 
> Changing the namespace is probably why this is failing.
> 
> If you need to change the namespace then you can use aliases:
> 
> @namespace("v2")
> protocol Service {
>   @aliases(["v1.Result"])
>   record Result { ... }
>   ...
> }
> 
> This will make v2 be able to read v1.
> 
> Doug

Mime
View raw message