Support Questions

Find answers, ask questions, and share your expertise

How to route file based on one column value

avatar

I have a incoming csv file which I need to route to different nifi flows based on the values in one of the column. Each csv has a column called "Country" which has same country name in all of its rows. What I want is 

File 1 - 50 rows (All rows will only one value in country column which will be any of the below)

England, england, Britain, UK, United kingdom, USA, United States 

So the file which contain values like England, england, Britain, UK, United kingdom in country column should be routed to one flow and if file contain USA or United States then it should be routed to another flow.

Note - One file will only contain one value in all rows. So routing based on first row value of country column for entire file is fine. How to achieve this?

1 ACCEPTED SOLUTION

avatar
Super Guru

@vikrant_kumar24 I believe the solution you are looking for is to use ExtractText to check for string matching the country you want in the first row.  This uses regex to match the entire file which you only need 1 match to know what country it is.   Using ExtractText to get an attribute called "country" you would when use RouteOnAttribute to create different country routes.  For example: usa => ${country.equals("usa").  Once your routes are defined you can pull them off RouteOnAttribute and send them down separate flows you create for each country.

 

You also should know that you can achieve the same logic of checking/defining/routing country by using QueryRecord.  Either method is suitable, but the latter method is more standard in the newest versions of nifi.

 

 

If this answer resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic. If you have further dialogue on this topic please comment here or feel free to private message me. If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.  

 

Thanks,


Steven @ DFHZ

View solution in original post

1 REPLY 1

avatar
Super Guru

@vikrant_kumar24 I believe the solution you are looking for is to use ExtractText to check for string matching the country you want in the first row.  This uses regex to match the entire file which you only need 1 match to know what country it is.   Using ExtractText to get an attribute called "country" you would when use RouteOnAttribute to create different country routes.  For example: usa => ${country.equals("usa").  Once your routes are defined you can pull them off RouteOnAttribute and send them down separate flows you create for each country.

 

You also should know that you can achieve the same logic of checking/defining/routing country by using QueryRecord.  Either method is suitable, but the latter method is more standard in the newest versions of nifi.

 

 

If this answer resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic. If you have further dialogue on this topic please comment here or feel free to private message me. If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.  

 

Thanks,


Steven @ DFHZ