Search code examples
jsonapache-nifijolt

Nifi Jolt convert after subtract


[
  {
    "dst_cnt": "149125"
  },
  {
    "src_cnt": "149136"
  },
  {
    "TABLENAME": "NAME"
  }
]

I want to subtract dst_cnt and src_cnt from this data with NIfi jolt. Is data operation possible after type conversion in NIfi?


Solution

  • Yes, it's possible. You can try the following transformatios spec

    [
      {
       // combine individual attributes within the common object
        "operation": "shift",
        "spec": {
          "*": {
            "*": "&"
          }
        }
      },
      {
       // sum up the the integer values after determining the negative form of "dst_cnt"
        "operation": "modify-overwrite-beta",
        "spec": {
          "dst_cnt_": "=divide(@(1,dst_cnt),-1)",
          "cnt_dif": "=intSum(@(1,dst_cnt_),@(1,src_cnt))"
        }
      },
      {
        // only pick the result derived from the subtraction 
        "operation": "shift",
        "spec": {
          "cnt_*": "&"
        }
      }
    ]