You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "Nándor Kollár (Jira)" <ji...@apache.org> on 2022/11/14 10:28: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=17633662#comment-17633662 ]
Nándor Kollár commented on AVRO-3654:
-------------------------------------
I think you missed the registration of decimal conversion for the logical type, something like this:
{code}
Schema bytesSchema = Schema.create(Schema.Type.BYTES);
LogicalTypes.decimal(10, 2).addToSchema(bytesSchema);
Schema nullableUuidSchema = Schema.createUnion(Schema.create(Schema.Type.NULL), bytesSchema);
Schema type2Schema = SchemaBuilder.record("record").fields().name("unionField").type(nullableUuidSchema).noDefault().endRecord();
BigDecimal bigDecimal = BigDecimal.valueOf(4042030.00);
GenericData.get().addLogicalTypeConversion(new Conversions.DecimalConversion());
GenericRecord record = new GenericData.Record(type2Schema);
record.put("unionField", bigDecimal);
Set<Object> map = new HashSet<>();
map.add(record);
{code}
> 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)