nifi:jolt:不同名称需要转换,每个名称的数组形成

问题描述 投票:0回答:1

这是我的输入和基于一个文件名路径,我们将对其进行分组并将这些相应的文件添加到每个组的单个数组中。

    [ {
        "filename" : "FF/raw/first/raw_A/filenameA_20240212002113.DAT"
      }, {
        "filename" : "FF/raw/first/raw_A/filenameA__20240205150101.DAT"
      }, {
        "filename" : "FF/raw/first/raw_B/filenameB_20240212002113.DAT"
      }, {
        "filename" : "FF/raw/first/raw_B/filenameB_20240205150101.DAT"
      } ]

and output is required in below format:

 [  {
        "raw_A": 
        [
        "filenameA_20240212002113.DAT",
        "filenameA_20240205150101.DAT"
        ]
    },
    {
        "raw_B":
        [
        "filenameB_20240212002113.DAT",
        "filenameB_20240205150101.DAT"
        ]
    }
]
apache-nifi jolt
1个回答
0
投票

您可以使用以下 shift 转换规范:

[
  { 
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*/*/*/*/*": "&(0,4).&(0,5)" // extract the leaf node by using 5th asterisk, eg. use &(0,5)
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "$": "[#2].&2.[#2]"
        }
      }
    }
  }
]
© www.soinside.com 2019 - 2024. All rights reserved.