使用 groovy 在 apache-nifi 中使用 executescript 处理器更新 csv 值失败 [英] Update csv value using executescript processor fails in apache-nifi using groovy

查看:49
本文介绍了使用 groovy 在 apache-nifi 中使用 executescript 处理器更新 csv 值失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与

QueryRecord csv 写入模式.

解决方案

如果你只想简单地更新字段值,那么使用 UpdateRecord 处理器.

当你输入如下文字时:

id,record_type1,02,03,1

然后将记录阅读器设置为 CSVReader,将 Schema Access Strategy 选项设置为 Use String Fields From Header.作家不在乎.UpdateRecord 处理器属性如下所示:

记录阅读器CSVReader记录写入器 CSVRecordSetWriter替代价值策略 文字价值/record_type ${field.value:replace('0','ORDER'):replace('1','COMPLAINT')}

这会给你预期的结果.

This question is related to this SO question

Above solution solved my problem, Now I tried to connect this into a flow coming from QueryRecord processor.

Here this QueryRecord divide my flowfile into two streams. Lets say customers and suppliers. And ExecuteGroovyScript is used to add ORDER and COMPLAINT.

Sample csv :

id,record_type
1,0
2,0
3,1

So result should be :

id,record_type
1,ORDER
2,ORDER
3,COMPLAINT

Actual result just placed default 'IGNORE' value.

QueryRecord configurations

QueryRecord csv write schema.

解决方案

If you just want to update the field value simply, then use UpdateRecord processor.

When you input the text as follows:

id,record_type
1,0
2,0
3,1

then setting the record reader to CSVReader with the option Schema Access Strategy to the Use String Fields From Header. The writer is not a concern. The UpdateRecord processor properties look like this:

Record Reader               CSVReader
Record Writer               CSVRecordSetWriter
Replacement Value Strategy  Literal Value
/record_type                ${field.value:replace('0','ORDER'):replace('1','COMPLAINT')}

This will give your expected result.

这篇关于使用 groovy 在 apache-nifi 中使用 executescript 处理器更新 csv 值失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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