MySQL表名称:ar_tmp
有两列id int
和name int
我执行sql
insert into ar_tmp (id, name) values (1, 4);
和CaptureChangeMySQL
捕获了这样的CDC和流内容
{
"type":"insert",
"timestamp":1550221517000,
"binlog_filename":"mysql-bin.013920",
"binlog_position":241518646,
"database":"platform_data",
"table_name":"ar_tmp",
"table_id":2899035,
"columns":[
{
"id":1,
"name":"id",
"column_type":4,
"value":1
},
{
"id":2,
"name":"name",
"column_type":4,
"value":4
},
{
"id":3,
"value":4
}
]
}
但是我想要这种格式的结果
{
"type":"insert",
"timestamp":1550221517000,
"binlog_filename":"mysql-bin.013920",
"binlog_position":241518646,
"database":"platform_data",
"table_name":"ar_tmp",
"table_id":2899035,
"columns":[
{
"id":1,
"name":4
}
]
}
或
{
"id":1,
"name":4
}
但是可能很难做到这一点,因为每一列都使用相同的代码来使处理器冗余(例如50列)。更糟糕的是,更改列名会很危险。
有什么想法吗?
答案 0 :(得分:0)
JoltTransformJSON可以在这里为您提供帮助。
尝试here
演示输入json的Jolt Spec:
[
{
"operation": "shift",
"spec": {
"columns": {
"*": {
"value": "columns.@(1,name)"
}
},
"*": "&"
}
}
]
结果是:
{
"type" : "insert",
"timestamp" : 1550221517000,
"binlog_filename" : "mysql-bin.013920",
"binlog_position" : 241518646,
"database" : "platform_data",
"table_name" : "ar_tmp",
"table_id" : 2899035,
"columns" : {
"id" : 1,
"name" : 4
}
}