You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Werner Daehn (JIRA)" <ji...@apache.org> on 2019/08/01 11:10:00 UTC

[jira] [Created] (AVRO-2495) Java: LogicalTypes not implemented nicely

Werner Daehn created AVRO-2495:
----------------------------------

             Summary: Java: LogicalTypes not implemented nicely
                 Key: AVRO-2495
                 URL: https://issues.apache.org/jira/browse/AVRO-2495
             Project: Apache Avro
          Issue Type: Improvement
          Components: java
    Affects Versions: 1.9.0
            Reporter: Werner Daehn


I'd like to use this Jira as a boilerplate for a couple of issues in the LogicalType handling. Will split those into individual ones, once it has been confirmed I am not completely wrong.

 

Generally speaking, the LogicalTypes and their backing with a native type is quite nice but from a usability point of view there are multiple areas where we could do better.
 # Provided LogicalTypes and custom LogicalTypes are handled differently. The latter are registered via LogicalTypes.register(), the provided ones are all hardcoded.
 # Java <–> Avro conversion is not nice. From a user perspective, I'd like to set a record via record.put("timestampmillis_column", LocalDateTime.now()); So by providing one of many possible value objects like Date, Instant, LocalDateTime,... even s proper formatted string. Another example is the amount of code you have to write in order to set a Decimal. When all the user wants is to say record.put("Quantity", 1.2). see below
 # toString() of a record does not consider LogicalTypes, e.g. a BigDecimal is shown as the backing \u0000\u00FF value instead of a human readable format.
 # Where ever a value is used, you have to check if there is a logical type. If not use the base type. This can be done better.
 # Lacking extension points. Imagine I want to extend the TimestampMillis LogicalType to add my own code. Not possible. First because how the LogicalType is created and second because constructors are private.

Do you agree or am I missing an important point?

 

{{{{DecimalConversion DECIMAL_CONVERTER = new DecimalConversion();
}}}}{{{{Schema s = item.getSchema().getField("Quantity").schema();
}}}}{{{{Decimal l = (Decimal) s.getLogicalType();
}}}}{{{{BigDecimal d = BigDecimal.valueOf(4.0).setScale(l.getScale());
}}}}{{{{ByteBuffer value = DECIMAL_CONVERTER.toBytes(d, null, l);
}}}}{{{{item.put("Quantity", value);}}}}



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)