json - Shift JOLT 转换 - 面临以下转换的问题
问题描述
我正在尝试将以下输入 json 转换为展平必要的列名及其值,同时保留所有元数据。
下面是我的 CDC 用例的输入 json 。
{
"type": "update",
"timestamp": 1558346256000,
"binlog_filename": "mysql-bin-changelog.000889",
"binlog_position": 635,
"database": "books",
"table_name": "publishers",
"table_id": 111,
"columns": [
{
"id": 1,
"name": "id",
"column_type": 4,
"last_value": 2,
"value": 2
},
{
"id": 2,
"name": "name",
"column_type": 12,
"last_value": "Suresh",
"value": "Suresh123"
},
{
"id": 3,
"name": "email",
"column_type": 12,
"last_value": "Suresh@yahoo.com",
"value": "Suresh@yahoo.com"
}
]
}
下面是预期的输出 json
[
{
"type": "update",
"timestamp": 1558346256000,
"binlog_filename": "mysql-bin-changelog.000889",
"binlog_position": 635,
"database": "books",
"table_name": "publishers",
"table_id": 111,
"columns": {
"id": "2",
"name": "Suresh123",
"email": "Suresh@yahoo.com"
}
}
]
我尝试了以下规范,我可以从中检索列对象,但不能检索其余的元数据。
[
{
"operation": "shift",
"spec": {
"columns": {
"*": {
"@(value)": "[#1].@(1,name)"
}
}
}
}
]
任何线索将不胜感激。
解决方案
我得到了上述转换的 JOLT 规范。如果有人偶然发现这样的事情,我会在这里发布它。
[
{
"operation": "shift",
"spec": {
"columns": {
"*": {
"@(value)": "columns.@(1,name)"
}
},
"*": "&"
}
}
]
推荐阅读
- webpack - 如何为动态子文件夹 js 和 scss 文件配置 webpack 并在各自的子文件夹名称中输出
- dart - 通用类型检查 - 保持类型而不是动态
- ios - Flutter IOS,CircleCI ARCHIVE 在将 Xcode 升级到 13.0.0 后失败
- reactjs - useStep 钩子函数不能与 onClick 箭头函数一起使用?
- android - 安装没有成功。无法安装应用程序。安装失败,原因是:“关闭”
- python - 部署谷歌云功能时出现EOFError
- c# - 更新页面时出现 Blazor Server System.ObjectDisposedException 问题
- python - 将 python 转换为包含单个单元格的 jupyter
- docker - 无法在 docker 容器内跟踪 .log 文件
- sql-server - 如何执行数据库 A/Server A 中存在的存储过程并同时查询数据库 B/Server B?