JOLT JSON 将单条记录转换为多条记录

JOLT JSON Transformation single record to multiple record

我要做以下改造。在此单条记录必须分成 3 部分。 cpu,用户又nice。但是需要在所有拆分中具有主机和时间戳的值,因为它们属于特定的 cpu、用户和 nice

输入

[
  {
    "timestamp": "2021-10-29T18:13:31",
    "host": "bbtpnj33",
    "cpu": "1",
    "user": "5.34",
    "nice": "0"
  },
  {
    "timestamp": "2021-10-29T18:13:32",
    "host": "bbtpnj34",
    "cpu": "2",
    "user": "10",
    "nice": "5"
  }
]

预期输出

[
  {
    "timestamp": "2021-10-29T18:13:31",
    "host": "bbtpnj33",
    "cpu": "1"
  },
  {
    "timestamp": "2021-10-29T18:13:31",
    "host": "bbtpnj33",
    "user": "5.34"
  },
  {
    "timestamp": "2021-10-29T18:13:31",
    "host": "bbtpnj33",
    "nice": "0"
  },
  {
    "timestamp": "2021-10-29T18:13:32",
    "host": "bbtpnj34",
    "cpu": "2"
  },
  {
    "timestamp": "2021-10-29T18:13:32",
    "host": "bbtpnj34",
    "user": "10"
  },
  {
    "timestamp": "2021-10-29T18:13:32",
    "host": "bbtpnj34",
    "nice": "5"
  }
]

我必须使用 NIFI JoltJsonTransformation 因为需要 JoltSpec。我确实尝试了很多,但没有得到有效的答案。我是 Jolt 的新手,请帮忙

我的 JOLT 表达式

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "cpu": "[&1][#1].cpu",
        "user": "[&1][#1].user",
        "nice": "[&1][#1].nice"
      }
    }
  }
]

对这三个属性(&1_&)和其他属性(&1)使用不同的限定符作为前缀,以便将它们分成两组以及下划线(_)等辅助字符,以便在下一次移位操作中用于区分。顺便说一句,不需要重复每个键名作为值,而是为每个键名使用一个符号。并在最后一步删除所有键,例如

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&1.&",
        "cpu": "&1_&.&",
        "user": "&1_&.&",
        "nice": "&1_&.&"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*_*": {
        "@(1,&(0,1).timestamp)": "&1.timestamp",
        "@(1,&(0,1).host)": "&1.host",
        "*": "&1.&"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": ""
    }
  }
]