Mule 4.2 - DWL 2.0 - groupBy 的结果需要删除 groupBy
Mule 4.2 - DWL 2.0 - After Result of groupBy need to remove groupBy
在 DWL 2.0 中执行 groupBy 操作后,我需要从实际数据中删除 groupBy 字段及其值。
例如
我有带有 json 数组的负载,例如:
[
{
"empId": 1,
"empName": "James",
"deptName": "Sales"
},
{
"empId": 2,
"empName": "ABC",
"deptName": "Marketing"
},
{
"empId": 3,
"empName": "BCD",
"deptName": "Account"
},
{
"empId": 4,
"empName": "EFG",
"deptName": "Sales"
},
{
"empId": 5,
"empName": "HIJK",
"deptName": "Account"
},
{
"empId": 6,
"empName": "LMN",
"deptName": "Sales"
},
{
"empId": 7,
"empName": "OPQR",
"deptName": "Marketing"
}
]
在此添加转换以执行 groupBy -->
<ee:transform doc:name="Transform Message">
<ee:message>
<ee:set-payload>
<![CDATA[%dw 2.0
output
application/json
---
(payload groupBy (item) -> item.customerId)
]]></ee:set-payload>
</ee:message>
</ee:transform>
这个转换的结果是-->
{
"Sales": [
{
"empId": 1,
"empName": "James",
"deptName": "Sales"
},
{
"empId": 4,
"empName": "EFG",
"deptName": "Sales"
},
{
"empId": 6,
"empName": "LMN",
"deptName": "Sales"
}
],
"Marketing": [
{
"empId": 2,
"empName": "ABC",
"deptName": "Marketing"
},
{
"empId": 7,
"empName": "OPQR",
"deptName": "Marketing"
}
],
"Account": [
{
"empId": 3,
"empName": "BCD",
"deptName": "Account"
},
{
"empId": 5,
"empName": "HIJK",
"deptName": "Account"
}
]
}
但是当您查看结果时,实际数据中不再需要 depetName 标签 json。我想从数据 json 中删除这个元素,并希望得到像 -->
这样的最终结果
{
"Sales": [
{
"empId": 1,
"empName": "James"
},
{
"empId": 4,
"empName": "EFG"
},
{
"empId": 6,
"empName": "LMN"
}
],
"Marketing": [
{
"empId": 2,
"empName": "ABC"
},
{
"empId": 7,
"empName": "OPQR"
}
],
"Account": [
{
"empId": 3,
"empName": "BCD"
},
{
"empId": 5,
"empName": "HIJK"
}
]
}
谁能帮我解决这个问题?
可以使用mapObject函数重新映射groupBy的结果,然后映射value组结果,去掉每个object中的字段
output application/json
---
payload groupBy ((item) -> item.deptName)
mapObject ((value, key, index) ->
{
(key): value map ((item, index) -> item - "deptName")
})
在 DWL 2.0 中执行 groupBy 操作后,我需要从实际数据中删除 groupBy 字段及其值。
例如
我有带有 json 数组的负载,例如:
[
{
"empId": 1,
"empName": "James",
"deptName": "Sales"
},
{
"empId": 2,
"empName": "ABC",
"deptName": "Marketing"
},
{
"empId": 3,
"empName": "BCD",
"deptName": "Account"
},
{
"empId": 4,
"empName": "EFG",
"deptName": "Sales"
},
{
"empId": 5,
"empName": "HIJK",
"deptName": "Account"
},
{
"empId": 6,
"empName": "LMN",
"deptName": "Sales"
},
{
"empId": 7,
"empName": "OPQR",
"deptName": "Marketing"
}
]
在此添加转换以执行 groupBy -->
<ee:transform doc:name="Transform Message">
<ee:message>
<ee:set-payload>
<![CDATA[%dw 2.0
output
application/json
---
(payload groupBy (item) -> item.customerId)
]]></ee:set-payload>
</ee:message>
</ee:transform>
这个转换的结果是-->
{
"Sales": [
{
"empId": 1,
"empName": "James",
"deptName": "Sales"
},
{
"empId": 4,
"empName": "EFG",
"deptName": "Sales"
},
{
"empId": 6,
"empName": "LMN",
"deptName": "Sales"
}
],
"Marketing": [
{
"empId": 2,
"empName": "ABC",
"deptName": "Marketing"
},
{
"empId": 7,
"empName": "OPQR",
"deptName": "Marketing"
}
],
"Account": [
{
"empId": 3,
"empName": "BCD",
"deptName": "Account"
},
{
"empId": 5,
"empName": "HIJK",
"deptName": "Account"
}
]
}
但是当您查看结果时,实际数据中不再需要 depetName 标签 json。我想从数据 json 中删除这个元素,并希望得到像 -->
这样的最终结果{
"Sales": [
{
"empId": 1,
"empName": "James"
},
{
"empId": 4,
"empName": "EFG"
},
{
"empId": 6,
"empName": "LMN"
}
],
"Marketing": [
{
"empId": 2,
"empName": "ABC"
},
{
"empId": 7,
"empName": "OPQR"
}
],
"Account": [
{
"empId": 3,
"empName": "BCD"
},
{
"empId": 5,
"empName": "HIJK"
}
]
}
谁能帮我解决这个问题?
可以使用mapObject函数重新映射groupBy的结果,然后映射value组结果,去掉每个object中的字段
output application/json
---
payload groupBy ((item) -> item.deptName)
mapObject ((value, key, index) ->
{
(key): value map ((item, index) -> item - "deptName")
})