【问题标题】:NIFI Jolt JSON date transformation not workingNIFI Jolt JSON 日期转换不起作用
【发布时间】:2021-11-30 10:51:28
【问题描述】:

在 Apache NIFI 数据流中,我尝试将日期从 MM-dd-yyyy 转换为 yyyy-MM-dd(MySQL 将接受作为日期的默认格式)。

在带有 DSL“链​​”的 JoltTransformJSON 1.15.0 处理器的 NIFI 高级编辑器中,我输入了:

输入Json:

{
  "Name": "Jan",
  "Birthday": "12-31-1994"
}

Transformation Jolt 脚本:

[{
    "operation": "modify-overwrite-beta",
    "spec": {
        "Birthday": "=${Birthday:toDate('MM-dd-yyyy'):format('yyyy-MM-dd')}"
    }
}]

结果:

{
  "Name": "Jan",
  "Birthday": "12-31-1994"
}

我没有收到任何语法错误。似乎 Jolt 转换并没有改变任何东西。 为什么生日没有变化?

【问题讨论】:

    标签: apache-nifi jolt


    【解决方案1】:

    您可以在 JoltTransformJSON 处理器的规范部分中使用以下连续规范

    [
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "b": "=split('-', @(1,Birthday))",
          "Birthday": "=concat(@(1,b[2]),'-',@(1,b[0]),'-',@(1,b[1]))"
        }
      },
      {
        "operation": "remove",
        "spec": {
          "b": ""
        }
      }
    ]
    

    where split 用破折号分割当前日期值,并在第一步中使用 concat 函数对其重新排序。然后去掉最后一步的辅助b属性

    【讨论】:

    • 感谢您的帮助 Özhan。此 Jolt 规范执行预期的转换。
    猜你喜欢
    • 2021-12-02
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    相关资源
    最近更新 更多