Aliases in the reader's schema are used to adapt the writer's schema.
Aliases in the writer's schema are not considered.  So your V2 can read V1
data, but not vice versa.  Is that what you're asking?

Thanks,

Doug

On Mon, Oct 22, 2018 at 1:01 PM Jesse Anderson <[email protected]>
wrote:

> The email subject should have been "Alias with Forward Compatibility." Are
> using aliases forward incompatible? I'm using Avro 1.8.2.
>
> Using Hotels.com's Avro compatibility checker, I get:
> com.hotels.avro.compatibility.SchemaCompatibilityException: Compatibility
> type 'CAN_BE_READ_BY' does not hold between 1 schema(s) in the chronology
> because: Schema[0] has incompatibilities: ['NAME_MISMATCH: expected:
> model.SimpleCardV2' at '/name','READER_FIELD_MISSING_DEFAULT_VALUE: suit'
> at '/fields/0'].
>
> Thanks,
>
> Jesse
>
> On Fri, Oct 19, 2018 at 4:17 PM Jesse Anderson <[email protected]>
> wrote:
>
>> Is adding an alias a backwards incompatible change? I have two schemas.
>> I'm going from V2 to V1 and getting an error that the field is missing. Am
>> I missing something again?
>>
>> Here is V1:
>> {
>>  "namespace": "model",
>>  "type": "record",
>>  "name": "SimpleCard",
>>  "fields": [
>>      {
>>        "name": "suit",
>>        "type": "string",
>>        "doc" : "The suit of the card"
>>      }
>>  ]
>> }
>>
>> Here is V2:
>> {
>>  "namespace": "model",
>>  "type": "record",
>>  "name": "SimpleCardV2",
>>  "aliases": ["SimpleCard"],
>>  "fields": [
>>      {
>>        "name": "cardsuit",
>>        "type": "string",
>>        "doc" : "The suit of the card",
>>        "aliases": ["suit"]
>>      }
>>  ]
>> }
>>
>> Here is the stack trace:
>> org.apache.avro.AvroTypeException: Found model.SimpleCardV2, expecting
>> model.SimpleCard, missing required field suit
>> at org.apache.avro.io.ResolvingDecoder.doAction(ResolvingDecoder.java:292)
>> at org.apache.avro.io.parsing.Parser.advance(Parser.java:88)
>> at
>> org.apache.avro.io.ResolvingDecoder.readFieldOrder(ResolvingDecoder.java:130)
>> at
>> org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:215)
>> at
>> org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:175)
>> at
>> org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:153)
>> at
>> org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:145)
>>
>> Thanks,
>>
>> Jesse
>>
>

Reply via email to