简体   繁体   English

Shift JOLT转换-以下转换面临的问题

[英]Shift JOLT transformation - facing problem with below transformation

I'm trying to convert below input json to flatten necessary column names and its values while retaining all metadata. 我试图将下面的输入json转换为展平必要的列名称及其值,同时保留所有元数据。

Below is the input json that I've for my CDC use-case. 以下是我为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"
    }
  ]
}

Below is the expected output json 以下是预期的输出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"
    }
  }
]

I tried the below spec from which I'm able to retrieve columns object but not the rest of the metadata. 我尝试了以下规范,可以从中检索column对象,但无法检索其余的元数据。

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

Any leads would be very much appreciated. 任何线索将不胜感激。

I got the JOLT spec for above transformation. 我得到了上述转换的JOLT规范。 I'm posting it here incase if anyone stumbles upon the something like this. 我将其发布在这里,以防万一有人偶然发现这样的东西。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM