我正试图从Dataweave 1.0迁移到2.0,请不要考虑给定DWL中的变量。我面临以下错误:
Unable to resolve reference of zeroPad2.
Unable to call `map` with (`Any`, ($, $$) -> `?`):
-
55| payload.DTOApplication.*DTOLossHistory[?($.@StatusCd == "Active")] default [] orderBy -($.@LossDt) map using (dispIdx = zeroPad2($$+1)) {
^^^^^^^^
- Unable to resolve reference of zeroPad2.
Actual: `map(items: `Array<T>`, mapper: (item: `T`, index: `Number`) -> `R`) -> `Array<R>``
-
55| payload.DTOApplication.*DTOLossHistory[?($.@StatusCd == "Active")] default [] orderBy -($.@LossDt) map using (dispIdx = zeroPad2($$+1)) {
^^^^^^^^
- Unable to resolve reference of zeroPad2.
Actual: `map(value: `Null`, mapper: (item: `Nothing`, index: `Nothing`) -> `Any`) -> `Null``
Dataweave 1.0:https://github.com/Manikandan99/Map_request/blob/main/Dataweave_1.0_Mule_3.dwl
我可以迁移除了第54行的之外的所有值
(
payload.DTOApplication.*DTOLossHistory[?($.@StatusCd == "Active")] default [] orderBy -($.@LossDt) map using (dispIdx = zeroPad2($$+1)) {
'CauseOfLoss$dispIdx': $.@LossCauseCd,
'DateOfLoss$dispIdx': $.@LossDt,
'IncurredAmt$dispIdx': $.@TotalIncurred
}
)
我正在尝试数据编织迁移:https://github.com/Manikandan99/Map_request/blob/main/Dataweave_2.0_mule_4.dwl
实际有效载荷:https://github.com/Manikandan99/Map_request/blob/main/input_xml_request_for_transformation.xml
关于如何将给定的dataweave 1.0迁移到2.0,有什么想法吗?
很明显,zeroPad2((不是DataWeave的内置函数。我可以有根据地猜测,这是Mule 3应用程序中的一个自定义全局MEL函数,它是从DataWeave 1.0脚本调用的。由于Mule 4不支持MEL函数,您需要在DataWeave 2.0(示例fun zeroPad2(n)=...
(中重新实现该函数才能完成相同的工作。从名称和参数来看,它只是用于在映射操作中用零填充索引的编号,因此重新实现相同的逻辑应该不会很困难。特别是因为它看起来甚至没有参数化要填充的位置的数量。
例如,您可以使用函数leftPad((中内置的DataWeave 2.0来实现类似的结果:
%dw 2.0
output application/json
import * from dw::core::Strings
fun zeroPad2(n)=leftPad(n, 2, "0")
---
zeroPad2(3)
输出:"03"
但是,除非逻辑更复杂,否则我建议在脚本中直接使用leftPad((,避免创建没有值的函数。
作为脚本中的一个例子,您可以用另一个函数调用或表达式替换zeroPad2((用法:
%dw 2.0
import * from dw::core::Strings
...
---
...map using (dispIdx = leftPad(n, $$+1, "0"))...
请记住,您没有提供zeroPad2((的详细信息,因此由您来实现类似的功能。