avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Korz (JIRA)" <j...@apache.org>
Subject [jira] [Created] (AVRO-1657) Namespaced reader schema w/field aliases can not read non-namespaced writer schema
Date Fri, 03 Apr 2015 00:05:54 GMT
David Korz created AVRO-1657:
--------------------------------

             Summary: 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)

Mime
View raw message