Apache NiFi 将 Epoch Unix 时间以秒为单位转换为毫秒并提取月份和年份?

Apache NiFi Transform Epoch Unix Time in Second to Milisecond and Extract the Month and the Year?

我有一个 JSON 这样的:

{
   ...
  "timestamp": 1613461012
   ...
}

时间戳是以秒为单位的纪元/unix 时间戳,而不是以毫秒为单位。

我想要这样的结果:

{
       ...
      "timestamp": 1613461012000 //timestamp in ms
      "monthyear": 2021-02 //it can be in any format as long as it can indicate the month and the year from the timestamp
       ...
}

我试过使用 Jolt Transform 来获取以毫秒为单位的时间戳:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "timestamp": "=divide(@(1,timestamp), 0.01)"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "timestamp": "=toInteger(@(1,timestamp))"
    }
  }
]

但它产生的结果是 2147483647 而不是 1613461012000(我认为这可能发生,因为 jolt 只能使用 int)。 对于提取月份和年份我还没有找到任何解决方案,我想我必须先在 ms 中获取纪元才能做到这一点。

有什么建议吗?

我终于可以解决这个问题了!这是我实现这一目标的方法。

完整的 Apache Nifi 模式:

EvaluateJSONPath 配置:

JoltTransformJSON

震动规格:

{
    "month.year": "${timestamp:toNumber():multiply(1000):format('yyyy-MM')}",
    "timestamp": ${timestamp:toNumber():multiply(1000)}
}