将unix时间戳转换为avro并将其存储在BigQuery中

时间:2019-06-07 10:05:38

标签: google-bigquery avro

Avro模式:

{
  "name": "Entity",
  "type": "record",
  "namespace": "com.foobar.entity",
  "fields": [
    {
      "name": "attribute",
      "type": "string"
    },
    {
      "name": "value",
      "type": "int"
    },
    {
      "name": "timestamp",
      "type": { "type": "long", "logicalType": "timestamp-micros" }
    }
  ]
}

源时间戳是Unix格式,精度为毫秒。

将此类记录放入BigQuery时,我在BigQuery数据预览中获得了1970-01-19 01:18:19.415 UTC之类的值。但是,我存储的值为1559899418Friday, 7. June 2019 09:23:38。有什么想法吗?

参考:https://cloud.google.com/bigquery/docs/loading-data-cloud-storage-avro#logical_types

1 个答案:

答案 0 :(得分:1)

您的时间戳偏离了1000倍。实际上,1559899418对应于Friday, 7. June 2019 09:23:38,但这是秒精度(Unix timestamp),而不是毫秒。 1559899(1559899418的千分之一)确实对应于1970-01-19 01:18:19