Snaplogic - 表达式语言语法 - 唯一的数组值

问题描述

我正在使用以下 EL

jsonPath($,"$array.map({id: value.get('id'),type: value.get('type') })")

产生下一个变量...

但是键(id)不是保持唯一的?!

        [{
            "id": "1","type": "1"
        },{
            "id": "1","type": "2"
        },{
            "id": "2","type": "1"
        }]

我可以在 snaplogic 表达式语言或 snap 中使用什么来获得以下唯一键数组:

           [{
                "id": "1","types": ["1","2"],{
                "id": "2","type": ["1"]
            }]

有什么想法吗?

解决方法

使用 Group By Fields 捕捉到基于 id 的分组,然后使用简单的映射器创建所需的 JSON。请注意,在进行分组之前,您必须按 id 对传入的文档进行排序。

样本管道

enter image description here

最终的 Mapper 表达式

$groupBy.id 映射到 id

jsonPath($,"$groups[*].type") 映射到类型

结果输出

enter image description here