【问题标题】:JOLT - Transform into output arrayJOLT - 转换成输出数组
【发布时间】:2021-03-25 02:32:35
【问题描述】:

我对 JOLT 有点陌生,一直在努力进行正确的转换。任何帮助表示赞赏。这是我的输入数据:

{
  "data": {
    "names": [
      "columnA",
      "columnB",
      "columnC",
      "columnD",
      "columnE",
      "columnF",
      "columnG",
      "columnH",
      "columnI",
      "columnJ",
      "columnK"
    ],
    "ndarray": [
      [
        0,
        1,
        2,
        "aString",
        "bString",
        3,
        4,
        "Text in English (A)",
        "Text in German (A)",
        "Error id A",
        "Error text A"
      ],
      [
        10,
        11,
        12,
        "cString",
        "dString",
        13,
        14,
        "Text in English (B)",
        "Text in German (B)",
        "Error id B",
        "Error text B"
      ]
    ]
  }
}

我的目标是创建一个包含所有条目的数组。对于此示例,将有 2 个条目(长度与 data.ndarray 相同)。数组 data.ndnames(键)和 data.ndarray[i](值)以 1:1 映射,即它们应该具有相同的长度。

这是预期的输出:

{
  "result": [
    {
      "columnA": 0,
      "columnG": 4,
      "columnC": 2,
      "columnF": 3,
      "explanation": [
        {
          "text": "Text in English (A)",
          "lang": "EN" // constant value
        },
        {
          "text": "Text in German (A)",
          "lang": "DE" // constant value
        }
      ],
      "columnD": "aString",
      "columnI": "Error id A",
      "columnJ": "Error text A"
    },
    {
      "columnA": 10,
      "columnG": 14,
      "columnC": 12,
      "columnF": 13,
      "explanation": [
        {
          "text": "Text in English (B)",
          "lang": "EN" // constant value
        },
        {
          "text": "Text in German (B)",
          "lang": "DE" // constant value
        }
      ],
      "columnD": "cString",
      "columnI": "Error id B",
      "columnJ": "Error text B"
    }
  ]
}

【问题讨论】:

    标签: apache-nifi jolt


    【解决方案1】:

    [编辑]试试这个规范:

    [
      {
        "operation": "shift",
        "spec": {
          "data": {
            "ndarray": {
              "*": {
                "*": {
                  "@": "result[&2].@(4,names[&1])"
                }
              }
            }
          }
        }
      },
      {
        "operation": "shift",
        "spec": {
          "result": {
            "*": {
              "columnH": "result[&1].explanation[0].text",
              "#EN": "result[&1].explanation[0].lang",
              "columnI": "result[&1].explanation[1].text",
              "#DE": "result[&1].explanation[1].lang",
              "columnB": null,
              "columnE": null,
              "columnJ": "result[&1].columnI",
              "columnK": "result[&1].columnJ",
              "*": "result[&1].&"
            }
          }
        }
      }
    ]
    

    【讨论】:

    • 我编辑了规范,我没有注意到 J,K 列应该上移到 I,J。现在应该是正确的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-28
    • 1970-01-01
    • 1970-01-01
    • 2020-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多