flipp-oss / deimos

Framework to work with Kafka, Avro and ActiveRecord
Other
59 stars 22 forks source link

timestamp-millis and timestamp-micros fields are serialized incorrectly #97

Closed jmccance closed 3 years ago

jmccance commented 3 years ago

When serializing an Avro message with fields that use the timestamp-millis or timestamp-micros logical types, the AvroSchemaCoercerer truncates Time types down to seconds since epoch instead of millis.

Example Schema

{
  "namespace": "my.company",
  "name": "Payload",
  "type": "record",
  "fields": [
    {
      "name": "timestamp-millis-field",
      "type": "long",
      "logicalType": "timestamp-millis"
    }
  ]
}

Message Hash

{
  'timestamp-millis-field' => Time.utc(2020, 11, 12, 13, 14, 15, 999000)
}

Expected Output

{
  "timestamp-millis-field": 1605186855999 // 2020-11-12T13:14:15.999Z
}

Actual Output

{
  "timestamp-millis-field": 1605186855 // 1970-01-19T07:53:06.000Z
}