Apache Nifi -json数组的JOLT规范

vfhzx4xs  于 2023-06-07  发布在  Apache
关注(0)|答案(1)|浏览(145)

我有一个JSON流文件,其中包含

[
  {
    "Ids": 9,
    "totalOut": 2,
    "outboundOut": 3,
    "timestamp": 98765
  },
  {
    "Ids": 34,
    "totalOut": 7,
    "outboundOut": 9,
    "timestamp": 98760
  },
  {
    "Ids": 54,
    "totalOut": 1,
    "outboundOut": 3,
    "timestamp": 98763
  }
]

我需要对totalOut的值,outboundOut的值分别求和,我需要对totalOut的值,outboundOut的值求和,并将其丰富为

{
  "totalout_sum": 10,
  "outbound_sum": 15,
  "total_sum": 25
}

帮我解决这个问题。

tjrkku2a

tjrkku2a1#

您可以使用以下转换规范

[
  { // convert attributes suffixed with "Out" to components of
    // the new independent arrays
    "operation": "shift",
    "spec": {
      "*": {
        "total*": "totalout_sum",
        "outbound*": "outbound_sum"
      }
    }
  },
  { // sum of the components of the array to generate desired attributes
    // namely "totalout_sum" and "outbound_sum"
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=intSum(@(1,&))"
    }
  },
  { // generate total sum of the values of the newly generated attributes
    "operation": "modify-overwrite-beta",
    "spec": {
      "total_sum": "=intSum(@(1,totalout_sum),@(1,outbound_sum))"
    }
  }
]

网站上的***演示***是

相关问题