gpt4 book ai didi

apache-kafka - 使用Kafka Connect时如何转换所有时间戳字段?

转载 作者:行者123 更新时间:2023-12-04 11:46:04 58 4
gpt4 key购买 nike

我正在尝试将所有时间戳字段转换为格式为 yyyy-MM-dd HH:mm:ss 的字符串类型.

要转换多个字段,我必须分别为每个字段创建一个转换。

...
"transforms":"tsFormat1,tsFormat2,...,tsFormatN",
"transforms.tsFormat1.type": "org.apache.kafka.connect.transforms.TimestampConverter$Value",
"transforms.tsFormat1.target.type": "string",
"transforms.tsFormat1.field": "ts_col1",
"transforms.tsFormat1.format": "yyyy-MM-dd HH:mm:ss",
"transforms.tsFormat2.type": "org.apache.kafka.connect.transforms.TimestampConverter$Value",
"transforms.tsFormat2.target.type": "string",
"transforms.tsFormat2.field": "ts_col2",
"transforms.tsFormat2.format": "yyyy-MM-dd HH:mm:ss",
...
"transforms.tsFormatN.type": "org.apache.kafka.connect.transforms.TimestampConverter$Value",
"transforms.tsFormatN.target.type": "string",
"transforms.tsFormatN.field": "ts_colN",
"transforms.tsFormatN.format": "yyyy-MM-dd HH:mm:ss",
...

有没有办法对所有时间戳列应用单个转换?

我试过了,
...
"transforms":"tsFormat",
"transforms.tsFormat.type": "org.apache.kafka.connect.transforms.TimestampConverter$Value",
"transforms.tsFormat.target.type": "string",
"transforms.tsFormat.field": "ts_col1, ts_col2,..., ts_colN",
"transforms.tsFormat.format": "yyyy-MM-dd HH:mm:ss",
...


...
"transforms":"tsFormat",
"transforms.tsFormat.type": "org.apache.kafka.connect.transforms.TimestampConverter$Value",
"transforms.tsFormat.target.type": "string",
"transforms.tsFormat.field": "ts_col1",
"transforms.tsFormat.field": "ts_col2",
...
"transforms.tsFormat.field": "ts_colN",
"transforms.tsFormat.format": "yyyy-MM-dd HH:mm:ss",
...



更好的是数字类型匹配 "numeric.mapping": "best_fit" .就像如何 numeric.mapping适用于所有数字字段(无需手动指定字段名称)以尝试找到最佳数字类型,是否有类似的东西可以对所有时间戳字段应用转换或字符串格式?

最佳答案

我在原始 TimestampConverter 的基础上做了一些调整, 就像你想要的那样完美:
https://github.com/howareyouo/kafka-connect-timestamp-converter

关于apache-kafka - 使用Kafka Connect时如何转换所有时间戳字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55460854/

58 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com