How to transform and extract fields in Kafka sink JDBC connector

前端 未结 2 456
梦如初夏
梦如初夏 2021-01-06 01:15

I am using a 3rd party CDC tool that replicates data from a source database into Kafka topics. An example row is shown below:

{  
   \"data\":{  
      \"US         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-06 01:24

    If you're willing to list specific field names, you can solve this by:

    1. Using a Flatten transform to collapse the nesting (which will convert the original structure's paths into dot-delimited names)
    2. Using a Replace transform with rename to make the field names be what you want the sink to emit
    3. Using another Replace transform with whitelist to limit the emitted fields to those you select

    For your case it might look like:

      "transforms": "t1,t2,t3",
      "transforms.t1.type": "org.apache.kafka.connect.transforms.Flatten$Value",
      "transforms.t2.type": "org.apache.kafka.connect.transforms.ReplaceField$Value",
      "transforms.t2.renames": "data.USER_ID:USER_ID,data.USER_CATEGORY:USER_CATEGORY,headers.operation:operation,headers.timestamp:timestamp",
      "transforms.t3.type": "org.apache.kafka.connect.transforms.ReplaceField$Value",
      "transforms.t3.whitelist": "USER_ID,USER_CATEGORY,operation,timestamp",
    

提交回复
热议问题