【发布时间】:2023-01-17 17:58:32
【问题描述】:
源 JSON(示例)我尝试将每条“连接”记录与每条“测试”记录结合起来。 (我是 JOLT 和堆栈溢出方面的初学者,所以请宽容 ;-)
{
"scen_id": 62,
"parameters": {
"name": "TWAMP_S1NR_VBEI",
"duration": 1,
"upload": 60,
"endless_duration": true,
"scen_id": 62
},
"connections": [
{
"synchro": false,
"manufacturer": 6,
"light": true,
"conn_id": 1,
"_id": "63051ddf26a5ce557ee2cf39",
"index": 0
},
{
"synchro": false,
"manufacturer": 6,
"light": true,
"conn_id": 2,
"_id": "63051ddf26a5ce557ee2cf38",
"index": 1
}
],
"tests": [
{
"name": "TOS30",
"test_id": 1,
"_id": "63051ddf26a5ce557ee2cf3a"
},
{
"name": "TOS31",
"test_id": 2,
"_id": "63051ddf26a5ce557ee2cf3a"
}
]
}
我试过的 JOLT 规范
我打算先遍历其中一个数组,然后将其与第二个数组的每条记录“相乘”。
[
{
"operation": "shift",
"spec": {
"connections": {
"*": {
"*": "&2.[&1].&",
"@(2,tests)": "&2.[&1].tests"
}
}
}
}
]
结果是这样的
我将整个第二个数组添加到 array1 的每个记录
{
"connections" : [ {
"tests" : [ {
"name" : "TOS30",
"test_id" : 1,
"_id" : "63051ddf26a5ce557ee2cf3a"
}, {
"name" : "TOS31",
"test_id" : 2,
"_id" : "63051ddf26a5ce557ee2cf3a"
} ],
"synchro" : false,
"manufacturer" : 6,
"light" : true,
"conn_id" : 1,
"_id" : "63051ddf26a5ce557ee2cf39",
"index" : 0
}, {
"tests" : [ {
"name" : "TOS30",
"test_id" : 1,
"_id" : "63051ddf26a5ce557ee2cf3a"
}, {
"name" : "TOS31",
"test_id" : 2,
"_id" : "63051ddf26a5ce557ee2cf3a"
} ],
"synchro" : false,
"manufacturer" : 6,
"light" : true,
"conn_id" : 2,
"_id" : "63051ddf26a5ce557ee2cf38",
"index" : 1
} ]
}
我所期望的
{
"connections": [
{
"synchro": false,
"manufacturer": 6,
"light": true,
"conn_id": 1,
"_id": "63051ddf26a5ce557ee2cf39",
"index": 0,
"name": "TOS30",
"test_id": 1,
"_id": "63051ddf26a5ce557ee2cf3a"
},
{
"synchro": false,
"manufacturer": 6,
"light": true,
"conn_id": 1,
"_id": "63051ddf26a5ce557ee2cf39",
"index": 0,
"name": "name": "TOS3",
"test_id": 2,
"_id": "63051ddf26a5ce557ee2cf3a"
},
{
"synchro": false,
"manufacturer": 6,
"light": true,
"conn_id": 2,
"_id": "63051ddf26a5ce557ee2cf38",
"index": 1,
"name": "TOS30",
"test_id": 1,
"_id": "63051ddf26a5ce557ee2cf3a"
},
{
"synchro": false,
"manufacturer": 6,
"light": true,
"conn_id": 2,
"_id": "63051ddf26a5ce557ee2cf38",
"index": 1,
"name": "name": "TOS3",
"test_id": 2,
"_id": "63051ddf26a5ce557ee2cf3a"
}
]
}
非常感谢每一个提示/解释!
【问题讨论】:
-
您不能在所需的输出中有两个相同的
_id键。 -
谢谢@Mohammad,是的!因此,我添加了另一个“前置步骤”,在将它们合并在一起之前,我将这些键设置为唯一
标签: apache-nifi transformation combine shift jolt