[
https://issues.apache.org/jira/browse/AVRO-2912?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Nir Barel updated AVRO-2912:
----------------------------
Description:
Hi,
I tried to convert a protobuf bytes array into avro GenericRecord.
I used the avro-protobuf lib to generate the schema of my protobuf.
When I tries to convert my bytes array into GenericRecord I get an exception of
*"org.apache.avro.AvroRuntimeException: Malformed data. Length is negative:
-25"*
Tried to debug this a bit, but couldn't tell why it fail on 1st field, I think
the lib reads from wrong place in the byte array and read only 5 bytes instead
of much more.
Stuff I checked:
1. I double check my proto bytes array by converting it into protobuf object or
JSON and data is valid.
2. I debug protobuf parseFrom() and for sure the 1st field is 38 chars and not
5 as avro fail on
3. I can't share my proto but my proto is 3.6.1 and includes fields of
primitive types like string and int but also any of section (many types of
objets)
Code:
{code:java}
ProtobufDatumReader<Proto> datumReader = new
ProtobufDatumReader<>(Proto.class);
GenericDatumReader<GenericRecord> genericDatumReader = new
GenericDatumReader<>(datumReader.getSchema());
GenericRecord record = genericDatumReader.read(null,
DecoderFactory.get().binaryDecoder(new ByteArrayInputStream(bytes), null));
{code}
was:
Hi,
I tried to convert a protobuf bytes array into avro GenericRecord.
I used the avro-protobuf lib to generate the schema of my protobuf.
When I tries to convert my bytes array into GenericRecord I get an exception of
"org.apache.avro.AvroRuntimeException: Malformed data. Length is negative: -25"
Tried to debug this a bit, but couldn't tell why it fail on 1st field.
I double check my proto bytes array by converting it into protobuf object or
JSON and data is valid.
snip of my code:
{code:java}
ProtobufDatumReader<Proto> datumReader = new
ProtobufDatumReader<>(Proto.class);
GenericDatumReader<GenericRecord> genericDatumReader = new
GenericDatumReader<>(datumReader.getSchema());
GenericRecord record = genericDatumReader.read(null,
DecoderFactory.get().binaryDecoder(new ByteArrayInputStream(bytes), null));
{code}
> Protobuf to Avro - throw an exception of
> "org.apache.avro.AvroRuntimeException: Malformed data. Length is negative:
> -25"
> ------------------------------------------------------------------------------------------------------------------------
>
> Key: AVRO-2912
> URL: https://issues.apache.org/jira/browse/AVRO-2912
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.9.2
> Reporter: Nir Barel
> Priority: Major
>
> Hi,
> I tried to convert a protobuf bytes array into avro GenericRecord.
> I used the avro-protobuf lib to generate the schema of my protobuf.
> When I tries to convert my bytes array into GenericRecord I get an exception
> of
> *"org.apache.avro.AvroRuntimeException: Malformed data. Length is negative:
> -25"*
> Tried to debug this a bit, but couldn't tell why it fail on 1st field, I
> think the lib reads from wrong place in the byte array and read only 5 bytes
> instead of much more.
>
> Stuff I checked:
> 1. I double check my proto bytes array by converting it into protobuf object
> or JSON and data is valid.
> 2. I debug protobuf parseFrom() and for sure the 1st field is 38 chars and
> not 5 as avro fail on
> 3. I can't share my proto but my proto is 3.6.1 and includes fields of
> primitive types like string and int but also any of section (many types of
> objets)
>
> Code:
> {code:java}
> ProtobufDatumReader<Proto> datumReader = new
> ProtobufDatumReader<>(Proto.class);
> GenericDatumReader<GenericRecord> genericDatumReader = new
> GenericDatumReader<>(datumReader.getSchema());
> GenericRecord record = genericDatumReader.read(null,
> DecoderFactory.get().binaryDecoder(new ByteArrayInputStream(bytes), null));
> {code}
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)