1
votes

enter image description hereI'm reading a CSV file in Apache Nifi and now i want to add a column which is serial number and this column will have the serial number for all the rows in the CSV file. So if i have 10 rows the serial number would from 1 to 10.How can i achieve this through Nifi? I've tried using getStateValue in the update processor but this gives me a static number. My UpdateAttribute and UpdateRecord are shown below.enter image description here

1
share your code please - Maelig
do want the xml code? - Ghost9
anything that can help people coming to help you - Maelig

1 Answers

2
votes

Use QueryRecord processor and processor supports Apache-Calcite SQL language.

Add new dynamic property to QueryRecord processor by using ROW_NUMBER() window clause.

Example:

select *,ROW_NUMBER() over(<optional orderby clause>) as seq from FLOWFILE

Define RecordReader and RecordWriter controller services in query record processor to include seq column in avro schema.

Output flowfile from queryrecord processor now will include seq column to the flowfile.