使用groovy在apache-nifi中使用executescript处理器更新csv值失败 [英] Update csv value using executescript processor fails in apache-nifi using groovy
问题描述
此问题与此SO问题
上述解决方案解决了我的问题,现在我尝试将其连接到来自QueryRecord
处理器的流中.
Above solution solved my problem, Now I tried to connect this into a flow coming from QueryRecord
processor.
在这里QueryRecord
将我的流文件分成两个流.假设customers
和suppliers
.然后ExecuteGroovyScript
用于添加ORDER
和COMPLAINT
.
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屋!