avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anders Sundelin <anders.sunde...@ericsson.com>
Subject Re: Evolving schemas and namespaces
Date Fri, 02 Dec 2016 15:43:34 GMT
Hi Niels and Elliot,

Thinking from the Java perspective now, the nice thing about namespaces 
(and, to a lesser degree, the name itself) is that they are mapped to 
packages (and classnames).

If the v1 Avro spec was used as a base for generating java classes, then 
the corresponding Java class would then be "com.example.some.v1.MyType",

and, correspondingly, the v2 Avro schema would generate into 
"com.example.some.v2.MyType"

In other words, clients (or servers) could happily use both classes 
while talking to different other peers (supporting, for instance, 
protocol negotiation).

This is the most important reason for why I think the rule you mention 
is kind of strange.

What do you others think?

BR

/Anders



On 2016-12-02 16:33, Elliot West wrote:
> There is perhaps a little ambiguity in the spec:
>
> From https://avro.apache.org/docs/current/spec.html#names
>   Record, enums and fixed are named types. Each has a fullname that is 
> composed of two parts; a name and a namespace.*Equality of names is 
> defined on the fullname*.
>
> From https://avro.apache.org/docs/current/spec.html#Schema+Resolution:
>   It is an error if the two schemas do not match.
>   To match, one of the following must hold:
>   ...
> *both schemas are records with the same name*
>   ...
>
> I suspect that in this case 'name' means 'fullname' and therefore by 
> choosing a different namespace you've declared to Avro that they 
> should be considered different types.
>
> If you are trying to annotate different schemas with a version 
> identifier, perhaps a 'doc' property might be more appropriate?
>
> On 2 December 2016 at 15:11, Niels Basjes <Niels@basjes.nl 
> <mailto:Niels@basjes.nl>> wrote:
>
>     Hi,
>
>     When I run the code below the output indicates that these two are incompatible in
terms of schema evolution.
>
>     The ONLY difference is the namespace (v1 and v2).
>
>     If I remove the namespace line the are reported as 'compatible'.
>
>     My question is why these two are considered to be incompatible?
>
>     @Test public void evolveTest()throws IOException {
>        Schema schemaV1 =new Schema.Parser().parse("{\n" +
>          " \"type\": \"record\",\n" +
>          " \"name\": \"Foo\",\n" +
>          " \"namespace\": \"nl.example.evoleschema.v1\",\n" +
>          " \"fields\": [ {\n" +
>          " \"name\": \"count\",\n" +
>          " \"type\": {\n" +
>          " \"type\": \"enum\",\n" +
>          " \"name\": \"Bar\",\n" +
>          " \"symbols\": [ \"ONE\", \"TWO\", \"THREE\"]\n" +
>          " }\n" +
>          " } ]\n" +
>          "}");
>
>        Schema schemaV2 =new Schema.Parser().parse("{\n" +
>          " \"type\": \"record\",\n" +
>          " \"name\": \"Foo\",\n" +
>          " \"namespace\": \"nl.example.evoleschema.v2\",\n" +
>          " \"fields\": [ {\n" +
>          " \"name\": \"count\",\n" +
>          " \"type\": {\n" +
>          " \"type\": \"enum\",\n" +
>          " \"name\": \"Bar\",\n" +
>          " \"symbols\": [ \"ONE\", \"TWO\", \"THREE\"]\n" +
>          " }\n" +
>          " } ]\n" +
>          "}");
>
>        LOG.info("{}", SchemaCompatibility.checkReaderWriterCompatibility(schemaV1, schemaV2).getType());
>        LOG.info("{}", SchemaCompatibility.checkReaderWriterCompatibility(schemaV2, schemaV1).getType());
>     }
>
>     -- 
>     Best regards / Met vriendelijke groeten, Niels Basjes
>

Mime
View raw message