You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "Christophe Le Saec (Jira)" <ji...@apache.org> on 2023/01/09 13:34:00 UTC

[jira] [Commented] (AVRO-3654) BigDecimal not supported in GenericData.getSchemaName() method

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

Christophe Le Saec commented on AVRO-3654:
------------------------------------------

Try with using GenericData singleton
{code:java}
GenericData.get().addLogicalTypeConversion(new Conversions.DecimalConversion());
{code}
instread of creating a new one.

> BigDecimal not supported in GenericData.getSchemaName() method
> --------------------------------------------------------------
>
>                 Key: AVRO-3654
>                 URL: https://issues.apache.org/jira/browse/AVRO-3654
>             Project: Apache Avro
>          Issue Type: Improvement
>          Components: java
>    Affects Versions: 1.11.1
>            Reporter: Emmanuel Brard
>            Priority: Critical
>
> When trying to add a `GenericRecord` in a Java set, the hashcode computation code is called.
> If a Union contains a decimal logical type which is mapped with a `BigDecimal` in Java, the call to `add` will fail with:
> {code}
> Caused by: org.apache.avro.AvroRuntimeException: Unknown datum type java.math.BigDecimal: 4042030.00
> 	at org.apache.avro.generic.GenericData.getSchemaName(GenericData.java:933)
> 	at org.apache.avro.generic.GenericData.resolveUnion(GenericData.java:892)
> 	at org.apache.avro.generic.GenericData.hashCode(GenericData.java:1113)
> 	at org.apache.avro.generic.GenericData.hashCodeAdd(GenericData.java:1127)
> 	at org.apache.avro.generic.GenericData.hashCode(GenericData.java:1103)
> 	at org.apache.avro.generic.GenericData.hashCode(GenericData.java:1113)
> 	at org.apache.avro.generic.GenericData.hashCodeAdd(GenericData.java:1127)
> 	at org.apache.avro.generic.GenericData.hashCode(GenericData.java:1103)
> 	at org.apache.avro.generic.GenericData$Record.hashCode(GenericData.java:292)
> 	at java.base/java.util.HashMap.hash(HashMap.java:338)
> 	at java.base/java.util.HashMap.put(HashMap.java:610)
> 	at java.base/java.util.HashSet.add(HashSet.java:221)
> {code}
> The method `getSchemaName` does not handle the BigDecimal Java type, which is used by the `DecimalConversion`.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)