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

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

问题描述

此问题与此SO问题

上述解决方案解决了我的问题,现在我尝试将其连接到来自QueryRecord处理器的流中.

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

在这里QueryRecord将我的流文件分成两个流.假设customerssuppliers.然后ExecuteGroovyScript用于添加ORDERCOMPLAINT.

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

csv示例:

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

所以结果应该是:

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

实际结果只是放置了默认的'IGNORE'值.

Actual result just placed default 'IGNORE' value.

QueryRecord配置

QueryRecord csv写模式.

QueryRecord csv write schema.

推荐答案

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

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

然后使用Use String Fields From Header的选项Schema Access Strategy将记录读取器设置为CSVReader.作者并不关心. UpdateRecord处理器属性如下:

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')}

这将给您预期的结果.

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

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