如何在NiFi中解析日期字段并以字符串格式生成日期 [英] How do I parse a date field and generate a date in string format in NiFi

查看:196
本文介绍了如何在NiFi中解析日期字段并以字符串格式生成日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的每个流文件包含2000条记录.我想将01/01/2000解析为一列year = 2000,一月month = Jan和一列day = 01

Each of my flow file contains 2000 records. I would like to parse 01/01/2000 into a column year = 2000, column month = Jan and column day = 01

即将输入列01/01/2000分为3个值,并用逗号01,Jan,2000

i.e. the input column 01/01/2000 into 3 values separated by commas 01,Jan,2000

推荐答案

让我们说,对于一个有生日的人,您具有这样的模式,并且您想分割生日:

Lets say you have a schema like this for a person with a birthday and you want to split out the birthday:

{
  "name": "person",
  "namespace": "nifi",
  "type": "record",
  "fields": [
    { "name": "first_name", "type": "string" },
    { "name": "last_name", "type": "string" },
    { "name": "birthday", "type": "string" }
  ]
}

您需要修改架构,使其具有要添加的字段:

You would need to modify the schema so it had the fields you want to add:

{
  "name": "person",
  "namespace": "nifi",
  "type": "record",
  "fields": [
    { "name": "first_name", "type": "string" },
    { "name": "last_name", "type": "string" },
    { "name": "birthday", "type": "string" },
    { "name": "birthday_year", "type": ["null", "string"] },
    { "name": "birthday_month", "type": ["null", "string"] },
    { "name": "birthday_day", "type": ["null", "string"] }
  ]
}

让我们说输入记录包含以下文本:

Lets say the input record has the following text:

bryan,bende,1980-01-01

我们可以将UpdateRecord与CsvReader和CsvWriter一起使用,并且UpdateRecord可以通过解析原始的生日字段来填充我们想要的三个字段.

We can use UpdateRecord with a CsvReader and CsvWriter, and UpdateRecord can populate the three fields we want by parsing the original birthday field.

如果将输出发送到LogAttribute,我们现在应该看到以下内容:

If we send the output to LogAttribute we should see the following now:

first_name,last_name,birthday,birthday_year,birthday_month,birthday_day
bryan,bende,1980-01-01,1980,01,01

以下是指向记录路径指南的链接,以获取有关toDate和格式功能的详细信息:

Here is the link to the record path guide for details on the toDate and format functions:

https://nifi.apache.org/docs/nifi-docs/html/record-path-guide.html

这篇关于如何在NiFi中解析日期字段并以字符串格式生成日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆