You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Iraj Hedayati (Jira)" <ji...@apache.org> on 2021/11/28 04:53:00 UTC
[jira] [Commented] (AVRO-3179) ClassCastException: java.math.BigDecimal cannot be cast to java.nio.ByteBuffer
[ https://issues.apache.org/jira/browse/AVRO-3179?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17449956#comment-17449956 ]
Iraj Hedayati commented on AVRO-3179:
-------------------------------------
[~rskraba] I'm not sure how you compiled your code snippet. The generated class of *Value* has {{setNomandat(java.nio.ByteBuffer value)}} method. You can't pass a {{java.math.BigDecimal}} there. It throws the same exception that [~MarcelKobain] reported. I modified your code to:
{code:java}
ByteBuffer v = new Conversions.DecimalConversion().toBytes(
new BigDecimal("1123"),
table.Value.getClassSchema().getField("nomandat").schema().getTypes().get(1),
LogicalTypes.decimal(16, 0)
);
table.Value v1 = table.Value.newBuilder().setNo("v1").setNomandat(v).build(); {code}
The cause of this bug is that in version 1.10.2, the following code is added to the generate POJO:
{code:java}
static {
MODEL$.addLogicalTypeConversion(new org.apache.avro.Conversions.DecimalConversion());
} {code}
The stack trace shows that it tries to read it without conversion but I need more info. I also tested this code:
{code:java}
Schema s = Decimal.builder(0).parameter("connect.decimal.precision", "16").build();
byte[] v3 = Decimal.fromLogical(s, new BigDecimal("1123"));
table.Value v2 = table.Value.newBuilder().setNo("v1").setNomandat(ByteBuffer.wrap(v3)).build(); {code}
which is basically is using Kafka connect.
what is the Kafka stream and Kafka connect version of yours? maybe share a few sample records that you have in your Postgres database. Which step is it failing? in Kafka connect or Kafka stream?
> ClassCastException: java.math.BigDecimal cannot be cast to java.nio.ByteBuffer
> ------------------------------------------------------------------------------
>
> Key: AVRO-3179
> URL: https://issues.apache.org/jira/browse/AVRO-3179
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.10.2
> Reporter: MarcelKobain
> Priority: Blocker
> Attachments: table.avsc
>
>
> Hello,
> I think we have the same problem as AVRO-2212.
> I have classCassException with a bigDecimal.
>
> Context :
> I am doing an ETL with postgres >> KafkaConnect >> KafkaStream
> I get schemas with mvn schema-registry:download
> I generate pojo with : mvn clean avro:schema
> Then I launch my app to stream a table source to a table target
> see schema here : [^table.avsc]
>
> I have fixed passing on the 1.10.1 version and it works. But When i take 1.10.2 I have the bug :
> Caused by: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.nio.ByteBufferCaused by: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.nio.ByteBuffer at postgres.table.Value.put(Value.java:240) at org.apache.avro.generic.GenericData.setField(GenericData.java:818) at org.apache.avro.specific.SpecificDatumReader.readField(SpecificDatumReader.java:139) at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:247) at org.apache.avro.specific.SpecificDatumReader.readRecord(SpecificDatumReader.java:123) at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:179)
>
>
--
This message was sent by Atlassian Jira
(v8.20.1#820001)