首页 > 解决方案 > 如何在 Kafka 连接中将微秒时间戳转换为毫秒?

问题描述

在使用confluentinc/kafka-connect-bigquery从 Kafka 填充 BigQuery 时,我想使用我们的域 (Avro) 事件的时间戳来 (day-) 对表进行分区。

我的connector.properties样子如下:

[...]
transforms=ConvertTimestamp
transforms.ConvertTimestamp.type=org.apache.kafka.connect.transforms.TimestampConverter$Value
transforms.ConvertTimestamp.field=metadata_date
transforms.ConvertTimestamp.target.type=Timestamp

timestampPartitionFieldName=metadata_date
[...]
Exception in thread "pool-5-thread-522" com.wepay.kafka.connect.bigquery.exception.BigQueryConnectException: table insertion failed for the following rows:
    [row index 0]: invalid: Timestamp field value is out of range:1597279521000000000
    [row index 1]: invalid: Timestamp field value is out of range:1597279523000000000
[...]

问题似乎是,我们的时间戳以微秒为单位(UTC Unix 纪元)

"type": {
    "type": "long",
    "logicalType": "timestamp-micros"
}

而 BigQuery 需要毫秒(或秒?)。

有没有办法直接使用连接器转换时间戳?

标签: apache-kafkagoogle-bigqueryavroapache-kafka-connectconfluent-schema-registry

解决方案


推荐阅读