Unable to serialise avro optional Decimal

See original GitHub issue

Describe the bug

Avro union types of Decimal do not serialise but throw

2021-10-18 17:51:46,311 ERROR [io.sma.rea.mes.kafka] (smallrye-kafka-producer-thread-0) SRMSG18212: Message org.eclipse.microprofile.reactive.messaging.Message$8@5702ccea was not sent to Kafka topic 'com.fnz.test.sink' - nacking message: org.apache.kafka.common.errors.SerializationException: Error serializing Avro message
Caused by: org.apache.avro.UnresolvedUnionException: Not in union ["null",{"type":"bytes","logicalType":"decimal","precision":13,"scale":6}]: 0.26268382480788643
	at org.apache.avro.generic.GenericData.resolveUnion(GenericData.java:877)
	at org.apache.avro.generic.GenericDatumWriter.resolveUnion(GenericDatumWriter.java:272)
	at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:143)
	at org.apache.avro.specific.SpecificDatumWriter.writeField(SpecificDatumWriter.java:98)
	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:210)
	at org.apache.avro.specific.SpecificDatumWriter.writeRecord(SpecificDatumWriter.java:83)
	at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:131)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:83)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:73)
	at io.confluent.kafka.serializers.AbstractKafkaAvroSerializer.serializeImpl(AbstractKafkaAvroSerializer.java:135)
	at io.confluent.kafka.serializers.KafkaAvroSerializer.serialize(KafkaAvroSerializer.java:61)
	at org.apache.kafka.common.serialization.Serializer.serialize(Serializer.java:62)
	at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:925)
	at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:885)
	at io.smallrye.reactive.messaging.kafka.impl.ReactiveKafkaProducer.lambda$send$3(ReactiveKafkaProducer.java:102)

Serialisers all seem to work when I use them directly - either using Avro or using the KafkaAvroSerializer but when they are used within quarkus messages fail to serialise

Expected behavior

serialised and sent messages

Actual behavior

Exception and messages not sent

How to Reproduce?

Check out project:

https://github.com/msillence/quarkus-avro-decimal-bug

docker-compose up -d

in the project home

add mskafka and schema-registry to your hosts file pointing to your localhost

Run the quarkus application and you will see serialisation errors every second

Run the unit tests and they all pass

Output of uname -a or ver

Linux JHC8700TP 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version “17” 2021-09-14

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.3.0.Final

Build tool (ie. output of mvnw --version or gradlew --version)

apache-maven-3.8.1

Additional information

I have been trying to capture how the serialiser is constructed in the tests here:

https://github.com/msillence/quarkus-avro-decimal-bug/blob/master/src/test/java/com/fnz/schema/SinkValueTest.java

specifically the first tests is meant to be similar to how the serialiser is constructed in quarkus but it all works under test so I feel this is difficult to pin on either avro or the confluent kafak serialiser

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
michalszynkiewiczcommented, Oct 20, 2021

@msillence thanks a lot for getting to the bottom of it!

0reactions
msillencecommented, Oct 21, 2021

1.11.0 release would also fix it when they build a release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avro failing to serialize BigDecimal as Decimal logicalType
I have a list of Avro objects and I'm trying to serialize them to json and write them to disk. Here is the...
Read more >
Decimal field with default value causes exception ... - GitHub
In my Kafka Connect schema I have a field of type Decimal with a default value of 1.23. This value and schema can...
Read more >
Avro Schema Serializer and Deserializer
This allows you to use JSON when human-readability is desired, and the more efficient binary format when storing data in topics.
Read more >
Using Apache Kafka with Schema Registry and Avro - Quarkus
This guide shows how your Quarkus application can use Apache Kafka, Avro serialized records, and connect to a schema registry (such as the...
Read more >
Apache Avro Data Source Guide - Spark 3.0.0-preview2 ...
The spark-avro module is external and not included in spark-submit or ... None, Optional Avro schema (in JSON format) that was used to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found