avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "peter liu (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (AVRO-1674) Optional field does not work in avro-cpp
Date Mon, 24 Aug 2015 04:08:45 GMT

     [ https://issues.apache.org/jira/browse/AVRO-1674?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

peter liu resolved AVRO-1674.
-----------------------------
    Resolution: Duplicate

> Optional field does not work in avro-cpp
> ----------------------------------------
>
>                 Key: AVRO-1674
>                 URL: https://issues.apache.org/jira/browse/AVRO-1674
>             Project: Avro
>          Issue Type: Bug
>          Components: c++
>    Affects Versions: 1.7.7
>            Reporter: Charlie Quillard
>
> I have to implement an optional field in my avro schema and when i test this one with
avro-py that works and that does not works with avro-cpp.
> That is my schema (cpx.json) :
> {code}
> {
>   "type" : "record",
>   "name" : "example",
>   "fields" : [
>     {
>       "name": "city",
>       "type": ["null", "string"],
>       "defaults":null
>     }
>   ]
> }
> {code}
> That is my cpp code:
> {code}
> typedef std::pair<avro::ValidSchema, avro::GenericDatum> Pair;
> int main(int ac, char **av)
> {
>     std::ifstream ifs("cpx.json");
>     avro::ValidSchema schema;
>     avro::compileJsonSchema(ifs, schema);
>     Pair p(schema, avro::GenericDatum());
>     avro::GenericDatum &Data = p.second;
>     Data = avro::GenericDatum(schema);
>     avro::GenericRecord &sReord = Data.value<avro::GenericRecord>();
>     sReord.setFieldAt(sReord.fieldIndex("city"), avro::GenericDatum("test"));
>     avro::DataFileWriter<Pair> dataFileWriter("test.bin", schema);
>     dataFileWriter.write(p);
>     dataFileWriter.close();
> }
> {code}
> This is my error when i transform my binary to json with avo-tools :
> {quote}
> Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
> 	at org.apache.avro.io.parsing.Symbol$Alternative.getSymbol(Symbol.java:402)
> 	at org.apache.avro.io.ResolvingDecoder.doAction(ResolvingDecoder.java:290)
> 	at org.apache.avro.io.parsing.Parser.advance(Parser.java:88)
> 	at org.apache.avro.io.ResolvingDecoder.readIndex(ResolvingDecoder.java:267)
> 	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:155)
> 	at org.apache.avro.generic.GenericDatumReader.readField(GenericDatumReader.java:193)
> 	at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:183)
> 	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)
> 	at org.apache.avro.file.DataFileStream.next(DataFileStream.java:220)
> 	at org.apache.avro.tool.DataFileReadTool.run(DataFileReadTool.java:77)
> 	at org.apache.avro.tool.Main.run(Main.java:84)
> 	at org.apache.avro.tool.Main.main(Main.java:73)
> {quote}



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

Mime
View raw message