Apache nifi 嵌套对象的颠簸变换
我希望o/p是这样的 1) 添加一个常量新字段“new_addition” 2) 将嵌套值“custom_tag.app_name”复制到上一级。 3) 将嵌套值“custom_tag.total_time”复制到上一级,但属性名称不同于“time_to_finish” 我无法找出这个的震动规格Apache nifi 嵌套对象的颠簸变换,apache-nifi,jolt,Apache Nifi,Jolt,我希望o/p是这样的 1) 添加一个常量新字段“new_addition” 2) 将嵌套值“custom_tag.app_name”复制到上一级。 3) 将嵌套值“custom_tag.total_time”复制到上一级,但属性名称不同于“time_to_finish” 我无法找出这个的震动规格 [ { "cluster_id": "0125-175512-node489", "custom_tag": { "app_name": "testing1",
[
{
"cluster_id": "0125-175512-node489",
"custom_tag": {
"app_name": "testing1",
"total_time": 32
}
},
{
"cluster_id": "0125-175512-node489",
"custom_tag": {
"app_name": "testing2",
"total_time": 34
}
}
]
确保您在流文件中添加了具有值的新属性
试试这个震动规范:
[
{
"cluster_id": "0125-175512-node489",
"app_name": "testing1",
"new_addition": "new const value",
"time_to_finish": 32,
"custom_tag": {
"app_name": "testing1",
"total_time": 32
}
},
{
"cluster_id": "0125-175512-node489",
"app_name": "testing2",
"new_addition": "new const value",
"time_to_finish": 34,
"custom_tag": {
"app_name": "testing2",
"total_time": 34
}
}
]
[{
"operation": "shift",
"spec": {
"*": "&", // get all elements
"custom_tag": {
"app_name": "app_name", //copy app_name to one level up
"total_time": "time_to_finish", //copy total_time to one level up and change name.
"@": "&" //get all the struct elements as is
}
}
}, {
"operation": "default",
"spec": {
"new_addition": "${new_addition}" //get the attribute value and add new_addition element to top level.
}
}]
输出:
[
{
"cluster_id": "0125-175512-node489",
"app_name": "testing1",
"new_addition": "new const value",
"time_to_finish": 32,
"custom_tag": {
"app_name": "testing1",
"total_time": 32
}
},
{
"cluster_id": "0125-175512-node489",
"app_name": "testing2",
"new_addition": "new const value",
"time_to_finish": 34,
"custom_tag": {
"app_name": "testing2",
"total_time": 34
}
}
]
[{
"operation": "shift",
"spec": {
"*": "&", // get all elements
"custom_tag": {
"app_name": "app_name", //copy app_name to one level up
"total_time": "time_to_finish", //copy total_time to one level up and change name.
"@": "&" //get all the struct elements as is
}
}
}, {
"operation": "default",
"spec": {
"new_addition": "${new_addition}" //get the attribute value and add new_addition element to top level.
}
}]
颠簸变换处理器配置:
[
{
"cluster_id": "0125-175512-node489",
"app_name": "testing1",
"new_addition": "new const value",
"time_to_finish": 32,
"custom_tag": {
"app_name": "testing1",
"total_time": 32
}
},
{
"cluster_id": "0125-175512-node489",
"app_name": "testing2",
"new_addition": "new const value",
"time_to_finish": 34,
"custom_tag": {
"app_name": "testing2",
"total_time": 34
}
}
]
[{
"operation": "shift",
"spec": {
"*": "&", // get all elements
"custom_tag": {
"app_name": "app_name", //copy app_name to one level up
"total_time": "time_to_finish", //copy total_time to one level up and change name.
"@": "&" //get all the struct elements as is
}
}
}, {
"operation": "default",
"spec": {
"new_addition": "${new_addition}" //get the attribute value and add new_addition element to top level.
}
}]
验证:
[
{
"cluster_id": "0125-175512-node489",
"app_name": "testing1",
"new_addition": "new const value",
"time_to_finish": 32,
"custom_tag": {
"app_name": "testing1",
"total_time": 32
}
},
{
"cluster_id": "0125-175512-node489",
"app_name": "testing2",
"new_addition": "new const value",
"time_to_finish": 34,
"custom_tag": {
"app_name": "testing2",
"total_time": 34
}
}
]
[{
"operation": "shift",
"spec": {
"*": "&", // get all elements
"custom_tag": {
"app_name": "app_name", //copy app_name to one level up
"total_time": "time_to_finish", //copy total_time to one level up and change name.
"@": "&" //get all the struct elements as is
}
}
}, {
"operation": "default",
"spec": {
"new_addition": "${new_addition}" //get the attribute value and add new_addition element to top level.
}
}]
以下各项工作正常
{
"cluster_id" : "0125-175512-node489",
"custom_tag" : {
"app_name" : "testing2",
"total_time" : 34
},
"app_name" : "testing2",
"time_to_finish" : 34,
"new_addition" : "new_addition"
}
您好,当输入是单个json元素时,它可以完美地工作。但如果输入是一个数组,它就不起作用。我把它作为一个o/p=>{“0”:{“集群id”:“0125-175512-node489”,“自定义标记”:{“应用程序名称”:“测试1”,“总时间”:32},“1”:{“集群id”:“0125-175512-node489”,“自定义标记”:{“应用程序名称”:“测试2”,“总时间”:34},“新添加”:“测试123}