The current Apache Avro (1.8.2) documentation mentions a "duration" logical type:
A duration logical type annotates Avro fixed type of size 12, which stores three little-endian unsigned integers that represent durations at different granularities of time. The first stores a number in months, the second stores a number in days, and the third stores a number in milliseconds.
While this all makes sense, I can't find an actual implementation in either the .Net or Java libraries. The documentation for logical types clearly lists every logical type except duration (date, time-millis, time-micros, timestamp-millis and timestamp-micros).
The "duration" is defined in my Avro schema accordingly:
{
"type": "record",
"name": "DataBlock",
"fields": [
{
"name": "duration",
"type": {
"type": "fixed",
"name": "DataBlockDuration",
"size": 12
}
}]
}
In .Net (excuse the VB), I have to manually serialise durations:
Dim ret(11) As Byte
Dim months = BitConverter.GetBytes(duration.Months)
Dim days = BitConverter.GetBytes(duration.Days)
Dim milliseconds = BitConverter.GetBytes(duration.Milliseconds)
Array.Copy(months, 0, ret, 0, 4)
Array.Copy(days, 0, ret, 4, 4)
Array.Copy(milliseconds, 0, ret, 8, 4)
When deserialising in Java, I have to convert to org.joda.time.Period by doing this:
IntBuffer buf = ByteBuffer
.wrap(dataBlock.getDuration().bytes())
.order(ByteOrder.LITTLE_ENDIAN)
.asIntBuffer();
Period period = Period
.months(buf.get(0))
.withDays(buf.get(1))
.withMillis(buf.get(2));
Am I missing something, or did the Avro team write a spec and forget to implement it? It seems that this data type in particular has to be implemented without any help from the Avro API at all.