Home > Back-end >  Nifi Jolt convert after subtract
Nifi Jolt convert after subtract

Time:08-24

[
  {
    "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?

CodePudding user response:

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_*": "&"
    }
  }
]
  • Related