Update csv value using executescript processor fails in apache-nifi using groovy

别来无恙 提交于 2019-12-12 18:14:44

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/58910020/update-csv-value-using-executescript-processor-fails-in-apache-nifi-using-groovy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!