简体   繁体   English

在 Nifi 中,如何从标签列表和包含所有记录的文件(每行一条记录)创建一个 JSON 流文件?

[英]In Nifi, how do I create a JSON flow file from a list of tags and a file containing all of the records, one record per line?

I have a semicolon-delimited file containing 1000 records, one record per line, with each record containing several fields delimited by semicolons.我有一个包含 1000 条记录的分号分隔文件,每行一条记录,每条记录包含几个由分号分隔的字段。 I also have a list of tags for the fields in the records.我还有记录中字段的标签列表。 How do I combine these into a JSON flow file in NiFi?如何在 NiFi 中将这些组合成一个 JSON 流文件?

Semicolon-delimited data file:分号分隔的数据文件:

r1f1;r1f2;r1f3;r1f4;r1f5
r2f1;r2f2;r2f3;r2f4;r2f5
r3f1;f3r2;r3f3;r3f4;r3f5
...

List of field tags:字段标签列表:

f1_tag, f2_tag, f3_tag, f4_tag, f5_tag

I can enter the list of tags into a processor block, but I am not sure which processor, if any, I can use.我可以将标签列表输入处理器块,但我不确定我可以使用哪个处理器(如果有的话)。

Sounds pretty basic.听起来很基本。 Use ConvertRecord with CSVReader as the Record Reader (don't forget to configure it to use semicolon as the Value Separator !) and set the Record Writer to be JsonRecordSetWriter and there you have it!使用带有ConvertRecordCSVReader作为Record Reader (不要忘记将其配置为使用分号作为Value Separator !)并将Record Writer器设置为JsonRecordSetWriter就可以了!

By the way, don't forget to add a header row!对了,不要忘记添加 header 行!

在此处输入图像描述 在此处输入图像描述 最后结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM