Details
-
Bug
-
Status: Open
-
Critical
-
Resolution: Unresolved
-
1.8.2
-
None
-
All (Linux and Windows)
-
1.8.2
-
Important
Description
The logical types date, time-millis, timestamp-millis are all handled properly with a converter. Specifying a schema and generate code results in a good constructor, which an use the proper types and serializatio e.g. from and to Json works as expected.
However if timestamp-micros, duration, decimal are used in the schema, there is no converter being generated.
Consider this schema
{
"type" : "record",
"name" : "TestRecordWithLogicalTypesBroken",
"doc" : "Schema from Avro Project - the three last fields are not properly converted",
"namespace" : "com.flink.ai.kafka.lab.types",
"fields" : [
,
{ "name" : "i32", "type" : "int" },
{ "name" : "i64", "type" : "long" },
{ "name" : "f32", "type" : "float" },
{ "name" : "f64", "type" : "double" },
{ "name" : "s", "type" : [ "null", "string" ], "default" : null }, {
"name" : "d",
"type" :
}, {
"name" : "t",
"type" :
}, {
"name" : "ts",
"type" :
}, {
"name" : "tsm",
"type" :
}, {
"name" : "dur",
"type" :
}, {
"name" : "dec",
"type" :
}]
}
It results in the following generated code: First the conversions:
private static final org.apache.avro.Conversion<?>[] conversions =
new org.apache.avro.Conversion<?>[]
;
Then also the constructor uses the underlying basic types.
public TestRecordWithLogicalTypesBroken(java.lang.Boolean b, java.lang.Integer i32, java.lang.Long i64, java.lang.Float f32, java.lang.Double f64, java.lang.CharSequence s, org.joda.time.LocalDate d, org.joda.time.LocalTime t, org.joda.time.DateTime ts, java.lang.Long tsm, com.flink.ai.kafka.lab.types.FixedDuration dur, java.nio.ByteBuffer dec)
{...}This is not in line with the documentation here:
https://avro.apache.org/docs/1.8.2/spec.html#Timestamp+%28microsecond+precision%29
https://avro.apache.org/docs/1.8.2/spec.html#Duration
https://avro.apache.org/docs/1.8.2/spec.html#Decimal
Do I somehow use the code generation wrong?
I also observed that in the test there is a frozen class
If I use the code generation with 1.8.2 I cannot reproduce this. Also note that it has a Decimal converter generated:
private final org.apache.avro.Conversion<?>[] conversions =
new org.apache.avro.Conversion<?>[]
;
I attach the schema that I used and the code that is generated from it.
Thanks for looking into this.