如何将输入 JSON 中的特定字段添加到 JOLT 规范以在 NIFI 中获得所需的输出?
How to add specific fields from input JSON to JOLT specification to get a desired output in NIFI?
我在获取正确数组的数据时遇到问题。
输入:
{ "type":"insert", "timestamp":1578899080000, "columns":[
{
"id":1,
"name":"id",
"column_type":4,
"value":3
},
{
"id":2,
"name":"title",
"column_type":-1,
"value":"mr"
},
{
"id":3,
"name":"first",
"column_type":-1,
"value":"todd"
},
{
"id":4,
"name":"last",
"column_type":-1,
"value":"graham"
},
{
"id":5,
"name":"street",
"column_type":-1,
"value":"5760 spring hill rd"
},
{
"id":6,
"name":"city",
"column_type":-1,
"value":"garden grove"
},
{
"id":7,
"name":"state",
"column_type":-1,
"value":"north carolina"
},
{
"id":8,
"name":"zip",
"column_type":-1,
"value":"81790"
},
{
"id":9,
"name":"gender",
"column_type":-1,
"value":"M"
},
{
"id":10,
"name":"email",
"column_type":-1,
"value":"todd.graham39@example.com"
},
{
"id":11,
"name":"username",
"column_type":-1,
"value":"purplekoala484"
},
{
"id":12,
"name":"password",
"column_type":-1,
"value":"paintball"
},
{
"id":13,
"name":"phone",
"column_type":-1,
"value":"(230)-874-6532"
},
{
"id":14,
"name":"cell",
"column_type":-1,
"value":"(186)-529-4912"
},
{
"id":15,
"name":"ssn",
"column_type":-1,
"value":"362-31-5248"
},
{
"id":16,
"name":"date_of_birth",
"column_type":93,
"value":"2006-07-25 05:48:01.0"
},
{
"id":17,
"name":"reg_date",
"column_type":93,
"value":"2004-12-05 11:26:34.0"
},
{
"id":18,
"name":"large",
"column_type":-1,
"value":"http://api.randomuser.me/portraits/men/39.jpg"
},
{
"id":19,
"name":"medium",
"column_type":-1,
"value":"http://api.randomuser.me/portraits/med/men/39.jpg"
},
{
"id":20,
"name":"thumbnail",
"column_type":-1,
"value":"http://api.randomuser.me/portraits/thumb/men/39.jpg"
},
{
"id":21,
"name":"version",
"column_type":-1,
"value":"0.6"
},
{
"id":22,
"name":"nationality",
"column_type":-1,
"value":"US"
}
] }
期望的输出:
[
{
"type":"insert",
"timestamp":1578899080000,
"id":6,
"title":"miss",
"first":"Amaira",
"last":"khan",
"street":"4524 hogan st",
"city":"iowa park",
"state":"ohio",
"zip":"24140",
"gender":"M",
"email":"guy.mckinney53@example.com",
"username":"blueduck623",
"password":"office",
"phone":"(309)-556-7859",
"cell":"(856)-764-9146",
"ssn":"973-37-9077",
"date_of_birth":"1983-11-03 22:02:12.0",
"reg_date":"2003-10-20 07:23:06.0",
"large":"http://api.randomuser.me/portraits/men/24.jpg",
"medium":"http://api.randomuser.me/portraits/med/men/24.jpg",
"thumbnail":"http://api.randomuser.me/portraits/thumb/men/24.jpg",
"version":"0.6",
"nationality":"US"
}
]
以下规范将执行您想要的操作@(1,name)
使用值作为键
[
{
"operation": "shift",
"spec": {
"type": "[0].type",
"timestamp": "[0].timestamp",
"columns": {
"*": {
"value": "[0].@(1,name)"
}
}
}
}
]
我在获取正确数组的数据时遇到问题。
输入:
{ "type":"insert", "timestamp":1578899080000, "columns":[
{
"id":1,
"name":"id",
"column_type":4,
"value":3
},
{
"id":2,
"name":"title",
"column_type":-1,
"value":"mr"
},
{
"id":3,
"name":"first",
"column_type":-1,
"value":"todd"
},
{
"id":4,
"name":"last",
"column_type":-1,
"value":"graham"
},
{
"id":5,
"name":"street",
"column_type":-1,
"value":"5760 spring hill rd"
},
{
"id":6,
"name":"city",
"column_type":-1,
"value":"garden grove"
},
{
"id":7,
"name":"state",
"column_type":-1,
"value":"north carolina"
},
{
"id":8,
"name":"zip",
"column_type":-1,
"value":"81790"
},
{
"id":9,
"name":"gender",
"column_type":-1,
"value":"M"
},
{
"id":10,
"name":"email",
"column_type":-1,
"value":"todd.graham39@example.com"
},
{
"id":11,
"name":"username",
"column_type":-1,
"value":"purplekoala484"
},
{
"id":12,
"name":"password",
"column_type":-1,
"value":"paintball"
},
{
"id":13,
"name":"phone",
"column_type":-1,
"value":"(230)-874-6532"
},
{
"id":14,
"name":"cell",
"column_type":-1,
"value":"(186)-529-4912"
},
{
"id":15,
"name":"ssn",
"column_type":-1,
"value":"362-31-5248"
},
{
"id":16,
"name":"date_of_birth",
"column_type":93,
"value":"2006-07-25 05:48:01.0"
},
{
"id":17,
"name":"reg_date",
"column_type":93,
"value":"2004-12-05 11:26:34.0"
},
{
"id":18,
"name":"large",
"column_type":-1,
"value":"http://api.randomuser.me/portraits/men/39.jpg"
},
{
"id":19,
"name":"medium",
"column_type":-1,
"value":"http://api.randomuser.me/portraits/med/men/39.jpg"
},
{
"id":20,
"name":"thumbnail",
"column_type":-1,
"value":"http://api.randomuser.me/portraits/thumb/men/39.jpg"
},
{
"id":21,
"name":"version",
"column_type":-1,
"value":"0.6"
},
{
"id":22,
"name":"nationality",
"column_type":-1,
"value":"US"
}
] }
期望的输出:
[
{
"type":"insert",
"timestamp":1578899080000,
"id":6,
"title":"miss",
"first":"Amaira",
"last":"khan",
"street":"4524 hogan st",
"city":"iowa park",
"state":"ohio",
"zip":"24140",
"gender":"M",
"email":"guy.mckinney53@example.com",
"username":"blueduck623",
"password":"office",
"phone":"(309)-556-7859",
"cell":"(856)-764-9146",
"ssn":"973-37-9077",
"date_of_birth":"1983-11-03 22:02:12.0",
"reg_date":"2003-10-20 07:23:06.0",
"large":"http://api.randomuser.me/portraits/men/24.jpg",
"medium":"http://api.randomuser.me/portraits/med/men/24.jpg",
"thumbnail":"http://api.randomuser.me/portraits/thumb/men/24.jpg",
"version":"0.6",
"nationality":"US"
}
]
以下规范将执行您想要的操作@(1,name)
使用值作为键
[
{
"operation": "shift",
"spec": {
"type": "[0].type",
"timestamp": "[0].timestamp",
"columns": {
"*": {
"value": "[0].@(1,name)"
}
}
}
}
]