首页 > 解决方案 > 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)"
        }
      }
    }
  }
]

任何线索将不胜感激。

标签: jsontransformationjolt

解决方案


我得到了上述转换的 JOLT 规范。如果有人偶然发现这样的事情,我会在这里发布它。

[
  {
    "operation": "shift",
    "spec": {
      "columns": {
        "*": {
          "@(value)": "columns.@(1,name)"
        }
      },
      "*": "&"
    }
  }
]

推荐阅读