gpt4 book ai didi

apache-nifi - Jolt json 转换问题。有一个里面有数组的记录,需要转换成记录数组

转载 作者:行者123 更新时间:2023-12-04 10:34:05 24 4
gpt4 key购买 nike

我需要在 NIFI 中转换一些流文件并想使用 Jolt 转换。我已经玩了一段时间了,无法找出可行的转换。我有...

{
"asset": "transformer1",
"readings": {
"oil_temp": 0.7499248991503604,
"otc_top_temp": 0.2870503485615279
},
"timestamp": "02/17/2020 19:07:31",
"key": "e2af07ab-4d21-4a70-ba3f-9113bb335d1e"
}

并且需要将其转换为这样的记录数组...
[
{
"tag": "transformer1.oil_temp",
"timestamp": "02/17/2020 19:07:31",
"value": 0.7499248991503604
},
{
"tag": "transformer1.otc_top_temp",
"timestamp": "02/17/2020 19:07:31",
"value": 0.2870503485615279
}
]


我希望这是可能的。我将不胜感激任何帮助。谢谢你。

最佳答案

您可以通过多个转换步骤来实现这一点:

  • 读数映射到列表
  • 使用 concat 操作创建新标签字段
  • 结果只传递您想要的值

  • 震动规范:
    [
    {
    "operation": "shift",
    "spec": {
    "readings": {
    "*": {
    "@(2,asset)": "[#2].asset",
    "$": "[#2].name",
    "@": "[#2].value",
    "@(2,timestamp)": "[#2].timestamp"
    }
    }
    }
    }, {
    "operation": "modify-default-beta",
    "spec": {
    "*": {
    "tag": "=concat(@(1,asset),'.',@(1,name))"
    }
    }
    }, {
    "operation": "shift",
    "spec": {
    "*": {
    "tag": "[&1].tag",
    "timestamp": "[&1].timestamp",
    "value": "[&1].value"
    }
    }
    }
    ]

    输入:
    {
    "asset": "transformer1",
    "readings": {
    "oil_temp": 0.7499248991503604,
    "otc_top_temp": 0.2870503485615279
    },
    "timestamp": "02/17/2020 19:07:31",
    "key": "e2af07ab-4d21-4a70-ba3f-9113bb335d1e"
    }

    输出:
    [ {
    "tag" : "transformer1.oil_temp",
    "timestamp" : "02/17/2020 19:07:31",
    "value" : 0.7499248991503604
    }, {
    "tag" : "transformer1.otc_top_temp",
    "timestamp" : "02/17/2020 19:07:31",
    "value" : 0.2870503485615279
    } ]

    在这里测试: https://jolt-demo.appspot.com/#inception

    关于apache-nifi - Jolt json 转换问题。有一个里面有数组的记录,需要转换成记录数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60272591/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com