json 如何在Apache NiFi中使用JoltSpecification中if else条件?

whitzsjs  于 2023-06-25  发布在  Apache
关注(0)|答案(1)|浏览(190)

我正在准备joltspecification,其中我需要实现if else条件。但是我无法达到预期的产量。请帮助我。
注意事项:
1.如果credits_type等于MARGINnull,则cost = pretax
1.否则cost + creditsamount = pretax
输入:

[
  {
    "cost": "10",
    "credits_amount": "5",
    "credits_type": "MARGIN"
  }
]

预期输出:

[
  {
    "cost": "10",
    "credits_amount": "5",
    "credits_type": "MARGIN",
    "pretax": "10"
  }
]
  • 这里pretax10,因为credits_type = MARGIN

谢谢

nszi6y05

nszi6y051#

您可以使用以下转换

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "credits_type": ["=notNull", "MARGIN"], // if it's Null(eg. else case of notNull) then assign MARGIN in order to combine the cases
        "xx_": "=intSum(@(1,credits_amount),@(1,cost))",
        "xx": "=toString(@(1,xx_))"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[&1].&",
        "credits_type": {
          "@": "[&2].&",
          "MARGIN": { "@2,cost": "[&3].pretax" },
          "*": { "@2,xx": "[&3].pretax" }
        }
      }
    }
  },
  { // get rid of the extra attributes "xx" and "xx_"
    "operation": "remove",
    "spec": {
      "*": {
        "x*": ""
      }
    }
  }
]

相关问题