json Apache Nifi中Jolt变换的IF-Else条件

mtb9vblg  于 2023-08-08  发布在  Apache
关注(0)|答案(1)|浏览(199)

我正在尝试使用jolt转换实现if-else条件以获得预期的输出,任何人都可以帮助我:
注意事项:
1.如果**billentity等于AWS Marketplace**
则**PriceToCustomer将等于0**
1.否则如果**billentity等于AWS**
则如果**LineItemType等于RecurringFee**
则**unblendedCost值将等于PriceToCustomer**
elseif**LineItemType等于tax**
则**(unblendedCost value * tax value/100) + 1等于PriceToCustomer**
否则**LineItemType等于Usage**
则**(unblendedCost value * Usage value/100) + 1将等于PriceToCustomer**

输入

[
  {
    "billentity": "AWS Marketplace",
    "lineItemType": "tax",
    "unblendedCost": 10,
    "tax": 5.02
  },
  {
    "billentity": "AWS",
    "lineItemType": "tax",
    "unblendedCost": 10,
    "tax": 8.02
  },
  {
    "billentity": "AWS",
    "lineItemType": "Usage",
    "unblendedCost": 10,
    "Usage": 9.02
  }
]

字符串

预期输出

[
  {
    "billentity": "AWS Marketplace",
    "lineItemType": "tax",
    "unblendedCost": 10,
    "tax": 5.02,
    "PriceToCustomer": 0
  },
  {
    "billentity": "AWS",
    "lineItemType": "tax",
    "unblendedCost": 10,
    "tax": 8.02,
    "PriceToCustomer": 1.802
  },
  {
    "billentity": "AWS",
    "lineItemType": "Usage",
    "unblendedCost": 10,
    "Usage": 9.02,
    "PriceToCustomer": 1.902
  }
]

bxfogqkk

bxfogqkk1#

可以在shift转换中使用条件逻辑,在modify转换中使用计算,例如

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "tmp_bl": "=concat(@(1,billentity),'_',@(1,lineItemType))",
        "tmp_dv_100_tax": "=divideAndRound(2,100,@(1,tax))",
        "tmp_dv_uc_100_tax": "=divideAndRound(3,@(1,unblendedCost),@(1,tmp_dv_100_tax))",
        "tmp_utt": "=doubleSum(@(1,tmp_dv_uc_100_tax),1)",
        "tmp_dv_100_usg": "=divideAndRound(2,100,@(1,Usage))",
        "tmp_dv_uc_100_usg": "=divideAndRound(3,@(1,unblendedCost),@(1,tmp_dv_100_usg))",
        "tmp_utu": "=doubleSum(@(1,tmp_dv_uc_100_usg),1)"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[&1].&",
        "tmp_bl": {
          "AWS Marketplace*": {
            "#0": "[&3].PriceToCustomer"
          },
          "AWS_tax": {
            "@2,tmp_utt": "[&3].PriceToCustomer"
          },
          "AWS_Usage": {
            "@2,tmp_utu": "[&3].PriceToCustomer"
          },
          "AWS_RecurringFee": {
            "@2,unblendedCost": "[&3].PriceToCustomer"
          }
        }
      }
    }
  },
  { // get rid of auxiliary attributes
    "operation": "remove",
    "spec": {
      "*": {
        "tmp_*": ""
      }
    }
  },
  { // convert non-numeric "PriceToCustomer" values to numeric ones
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "PriceToCustomer": "=toDouble"
      }
    }
  }
]

字符串
网站http://jolt-demo.appspot.com/上的 * 演示 * 是:


的数据

相关问题