[英]Kafka Mongo Sink connector , how to use SMT timestampconverter for the date filed inside a JSON array
"transforms": "TimestampConverter", “转换”:“时间戳转换器”,
"transforms.TimestampConverter.type": "org.apache.kafka.connect.transforms.TimestampConverter$Value",
"transforms.TimestampConverter.format": "yyyy-MM-dd",
"transforms.TimestampConverter.target.type": "string",
"transforms.TimestampConverter.field" : "DateAtlevel2"
When this date filed is at parent level of JSON the SMT works fine, its not working when Date filed inside a JSOn array.当此日期归档在 JSON 的父级别时,SMT 工作正常,当日期归档在 JSOn 数组中时,它不起作用。
How to apply the SMT to convert a filed inside JSON array into a Date?如何应用 SMT 将 JSON 数组中的文件转换为日期?
I am using Kafka Mongo Sink connector.我正在使用 Kafka Mongo Sink 连接器。
I assume that you are using the org.apache.kafka.connect.json.JsonConverter.java
which is a schemaless converter.我假设您使用的是
org.apache.kafka.connect.json.JsonConverter.java
这是一个无模式转换器。 In this case, you would only be able to retrieve the level 1 fields.在这种情况下,您将只能检索级别 1 字段。
Why?为什么? During the SMT phase, each record is stripped down to a plain Map<String, Object>, where
String
is the field name and the Object
is its value.在 SMT 阶段,每条记录都被剥离为一个普通的 Map<String, Object>,其中
String
是字段名称, Object
是它的值。 What the TimestampConverter does is to simply do a get on that map with the field name that you've passed as a config ( map.get("DateAtlevel2")
) which it can't be found. TimestampConverter 所做的只是简单地使用您作为配置传递的字段名称(
map.get("DateAtlevel2")
)获取 map ,但它无法找到。
To get access to level 2+ fields you would need some other type of input data that supports schemas ( AVRO, JSONSchema, or Protobuff ).要访问级别 2+ 字段,您需要一些其他类型的支持模式(AVRO、JSONSchema 或 Protobuff)的输入数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.