avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Everett Anderson <ever...@nuna.com>
Subject Decimal types in IDL and generated Java not carrying logical types to schemas
Date Mon, 30 May 2016 19:43:21 GMT
Hi,

I was trying out the decimal Logical Type in 1.8.1 in an example record
schema and noticed that while the logical type's information is preserved
in the JSON properties, it isn't actually respected or returned from the
Schema accessor.

Is it supported to use logical types in the IDL or are they primarily for
internal use? Is there a better way to specify decimal types in the IDL?

Example: user.avsc

{
 "namespace": "example.avro",
 "type": "record",
 "name": "User",
 "fields": [
     {
       "name": "name", "type": "string"
     },
     {
       "name": "account_balance",
       "type": "bytes",
       "logicalType": "decimal",
       "precision": 4,
       "scale": 2
     }
 ]
}

In the generated code,

User.getClassSchema().getField("account_balance").schema().getLogicalType();

is null. The Schema.Field's 'props' map from the JSON retains
'logicalType', 'precision', and 'scale', but its schema() doesn't have this
info or a non-null logical type member.

It looks like maybe the Schema.parse() code that parses the JSON only looks
for 'logicalType' in a record type, and when it recurses down, it only sees
this as a primitive 'bytes' type --

https://github.com/apache/avro/blob/branch-1.8/lang/java/avro/src/main/java/org/apache/avro/Schema.java#L1326

Mime
View raw message