【问题标题】:Apache Nifi: Update Record - Check null and replace with another parameterApache Nifi:更新记录 - 检查 null 并替换为另一个参数
【发布时间】:2021-12-13 18:53:26
【问题描述】:

我正在使用 Apache Nifi 进行 ETL 作业。在我的数据结构中,由于遗留数据,很少有字段为空或空。我想用一些逻辑数据填充它们。数据如下:

[
  {
    "id": 1234,
    "business_date": "2021-11-30",
    "order_date_time": "2021-11-30 12:10:45"
  },
  {
    "id": 1,
    "business_date": null,
    "order_date_time": "2009-10-12 01:02:03"
  },
  {
    "id": 2,
    "business_date": "",
    "order_date_time": "2007-01-02 03:04:05"
  }
]

最终结果应该如下:

[
  {
    "id": 1234,
    "business_date": "2021-11-30",
    "order_date_time": "2021-11-30 12:10:45"
  },
  {
    "id": 1,
    "business_date": "2009-10-12",
    "order_date_time": "2009-10-12 01:02:03"
  },
  {
    "id": 2,
    "business_date": "2007-01-02",
    "order_date_time": "2007-01-02 03:04:05"
  }
]

所以根据order_date_time,需要导出business_day,如果它为null或为空。

我读完了https://nifi.apache.org/docs/nifi-docs/html/record-path-guide.html 一切都是独立的,无法构造解决方案。

使用具有以下详细信息的 UpdateRecord 处理器:

/business_date --> ${field.value:isEmpty():format(/order_date_time, "YYYY-mm-dd")}

但这似乎不起作用

谁能教教如何做到这一点?

【问题讨论】:

标签: apache-nifi


【解决方案1】:

format 接受数字或日期对象作为第一个参数。

在链接中,您可以找到以下示例:

{
  "eventDate" : 1508457600000
}

表达式

format( /eventDate, "yyyy-MM-dd")                                   =>  2017-10-20

要使用日期,您必须首先从字符串中解析它

{
  "eventDate" : "2017-10-20 01:02:03"
}

表达式

format( toDate(/eventDate, "yyyy-MM-dd HH:mm:ss"), 'yyyy-MM-dd')    =>  2017-10-20

所以,在你的情况下必须使用format ( toDate )

或者你可以简单地使用substring

/business_date --> ${field.value:isEmpty():substring(/order_date_time, 0, 10)}

【讨论】:

    【解决方案2】:

    在下面的表达式中使用 记录值路径 策略

    /business_date --> coalesce(/business_date, format(toDate(/order_date_time, "yyyy-MM-dd HH:mm:ss"), 'yyyy-MM-dd'))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多