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

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

问题描述

我的每个流文件都包含 2000 条记录.我想将 01/01/2000 解析为列年 = 2000,列月 = Jan 和列日 = 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天全站免登陆