[ 
https://issues.apache.org/jira/browse/AVRO-1657?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14393782#comment-14393782
 ] 

David Korz commented on AVRO-1657:
----------------------------------

The problem is that in org.apache.avro.Schema.applyAliases(Schema,Map,Map,Map) 
the call to getFieldAlias() passes the Name of the writer schema and the 
fieldAliases map has an entry keyed with the reader's namespaced Name so no 
alias is found for the field TemperatureC.

> Namespaced reader schema w/field aliases can not read non-namespaced writer 
> schema
> ----------------------------------------------------------------------------------
>
>                 Key: AVRO-1657
>                 URL: https://issues.apache.org/jira/browse/AVRO-1657
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.7.7
>            Reporter: David Korz
>
> The writer uses a non-namespaced schema as follows:
> {noformat}
> { 
>     "type":"record",
>     "name": "MyRecord",
>     "fields":[
>         {
>             "type":"string",
>             "name":"Name"
>         },
>         {
>             "type":"double",
>             "name":"Temperature"
>         }
>      ]
> }
> {noformat}
> The reader uses a namespaced schema with a field alias.
> {noformat}
> { 
>     "type":"record",
>     "name": "MyRecord",
>     "namespace": "com.example",
>     "aliases": [".MyRecord"],
>     "fields":[
>         {
>             "type":"string",
>             "name":"Name"
>         },
>         {
>             "type":"double",
>             "name":"TemperatureC",
>             "aliases": ["Temperature"]
>         }
>      ]
> }
> {noformat}
> The following reading code will fail.
> {noformat}
> DatumReader<MyRecord> datumReader = new SpecificDatumReader<>(MyRecord.class);
> FileReader<MyRecord> fileReader = DataFileReader.openReader(file, 
> datumReader);
>         
> MyRecord record = null;
> while (fileReader.hasNext()) {
>     record = fileReader.next(record);
>     CharSequence name = record.getName();
>     Double temp = record.getTemperatureC();
>     System.out.println(name + " " + temp);
> }
> {noformat}
> The reader's alias is not found.
> {noformat}
> Exception in thread "main" org.apache.avro.AvroTypeException: Found MyRecord, 
> expecting com.example.MyRecord, missing required field TemperatureC
>       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:176)
>       at 
> org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:151)
>       at 
> org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:142)
>       at org.apache.avro.file.DataFileStream.next(DataFileStream.java:233)
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to