无法解析 zeroPad2 的引用和无法调用 `map` with (`Any`, ($, $$) -> `?`) 错误在 mule 4

Unable to resolve reference of zeroPad2 and Unable to call `map` with (`Any`, ($, $$) -> `?`) error in mule 4

我正在尝试从 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 的 built-in 函数。我可以做出有根据的猜测,这是从 DataWeave 1.0 脚本调用的 Mule 3 应用程序中的自定义全局 MEL 函数。由于 Mule 4 不支持 MEL 函数,您将需要在 DataWeave 2.0(示例 fun zeroPad2(n)=...)中重新实现该函数才能完成相同的工作。从名称和参数来看,只是用来在map操作中用零填充索引的编号,所以重新实现相同的逻辑应该不难。特别是因为它看起来甚至没有参数化要填充的位置数。

例如,您可以使用 DataWeave 2.0 内置函数 leftPad() 来实现类似的结果:

%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() 的详细信息,因此由您来实现类似的功能。