Charlie Quillard created AVRO-1674: -------------------------------------- Summary: 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 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 when i test without fill my field: {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>(); 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)