avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karthik (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (AVRO-2095) Avro 1.8.2 encode in c++ - java.lang.ArrayIndexOutOfBoundsException
Date Wed, 11 Oct 2017 01:27:01 GMT

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

Karthik edited comment on AVRO-2095 at 10/11/17 1:26 AM:
---------------------------------------------------------

Hi [~thiru_mg], Thanks for your prompt response.

 The reason I did not define the MyDevice in-line (inside the Event schema) is, MyDevice schema
will be used several times by other records (like event) in the actual schema definition.
So the idea was to define it once and then reference it everywhere using the name (com.test.MyDevice).
Please correct me if I am wrong ! 


was (Author: karthikus):
Hi [~thiru_mg], Thanks for your prompt response.

 The reason I did not define the MyDevice in-line (inside the Event schema) is, MyDevice schema
will be used several times by other records (like event) in this schema. So the idea was to
define it once and then reference it everywhere using the name (com.test.MyDevice). Please
correct me if I am wrong ! 

> Avro 1.8.2 encode in c++ -  java.lang.ArrayIndexOutOfBoundsException
> --------------------------------------------------------------------
>
>                 Key: AVRO-2095
>                 URL: https://issues.apache.org/jira/browse/AVRO-2095
>             Project: Avro
>          Issue Type: New Feature
>          Components: c++, java
>    Affects Versions: 1.8.2
>         Environment: C++, Java
>            Reporter: Karthik
>            Assignee: Thiruvalluvan M. G.
>              Labels: newbie
>
> I have the following schema
> {code:json}
> [
>     {
>         "namespace": "com.test",
>         "name": "MyDevice",
>         "type": "record",
>         "doc": "client device",
>         "fields": [
>             {
>                 "name": "deviceId",
>                 "type": [
>                     "null",
>                     "string"
>                 ],
>                 "default": null,
>                 "doc": "Usually unique MAC address"
>             }
>         ]
>     },
>     {
>         "namespace": "com.test",
>         "name": "Event",
>         "type": "record",
>         "doc": "event",
>         "fields": [
>             {
>                 "name": "myDevice",
>                 "type": [
>                     "null",
>                     "com.test.MyDevice"
>                 ],
>                 "default": null,
>                 "doc": "Device information"
>             }
>         ]
>     }
> ]
> {code}
> I installed avro 1.8.2 on my ubuntu build machine and generated test.h using avrogencpp
tool. 
> Then, I created binary encoded avro data as follows:
> {code:c++}
>     MyDevice device;
>     device.deviceId.set_string("device1");
>     Event event;
>     event.myDevice.set_MyDevice(device);
>     std::vector<char> bytes;
>     std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream(1);
>     avro::EncoderPtr e = avro::binaryEncoder();
>     e->init(*out);
>     avro::encode(*e, event);
>     out->flush();
> {code}
> I deserialize my data in Java application as follows:
> {code:java}
> Schema schema = SchemaUtils.getSchemaFromFile("src/main/resources/schemas/test.avsc");
> DatumReader<GenericRecord> genericDatumReader = new GenericDatumReader<>(schema);
>         Decoder decoder = DecoderFactory.get().binaryDecoder(data, null);
>         try {
>             GenericRecord userData = genericDatumReader.read(null, decoder);
>             System.out.println(userData);
>         } catch (IOException e) {
>             e.printStackTrace();
>         }
> {code}
> And the result is 
> {noformat}
> java.lang.ArrayIndexOutOfBoundsException: 7
> 	at org.apache.avro.io.parsing.Symbol$Alternative.getSymbol(Symbol.java:424)
> 	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.readWithoutConversion(GenericDatumReader.java:179)
> 	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:153)
> 	at org.apache.avro.generic.GenericDatumReader.readField(GenericDatumReader.java:232)
> 	at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:222)
> 	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.readWithoutConversion(GenericDatumReader.java:179)
> 	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:153)
> 	at org.apache.avro.generic.GenericDatumReader.readField(GenericDatumReader.java:232)
> 	at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:222)
> 	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.readWithoutConversion(GenericDatumReader.java:179)
> 	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:153)
> 	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:145)
> {noformat}
> But if I do the same using a simple schema (without union), it works perfectly
> {code:json}
> {
>         "namespace": "com.test",
>         "name": "MyDevice",
>         "type": "record",
>         "doc": "client device",
>         "fields": [
>             {
>                 "name": "deviceId",
>                 "type": [
>                     "null",
>                     "string"
>                 ],
>                 "default": null,
>                 "doc": "Usually unique MAC address"
>             }
>         ]
>     }
> {code}
> Any help appreciated ! Thanks ! 



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message