Only saving files without null value on Nifi

Viewed 35

an absolute newbie here trying out Nifi and postgresql on docker compose.

I have a sample CSV file with 4 columns. I want to split this CSV file into two based on whether if it contains a row with null value or not.

Grade   ,BreedNm       ,Gender      ,Price
C++     ,beef_cattle   ,Female      ,10094
C++     ,milk_cow      ,Female      ,null
null    ,beef_cattle   ,Male        ,12704
B++     ,milk_cow      ,Female      ,16942

for example, above table should be split into two tables each containing row 1,4 and 2,3 and save each of them into a Postgresql table.

Below is what I have tried so far.

I was trying to

  1. split flowfile into 2 and only save rows without null value on left side and with null values on right side.
  2. Write each of them into a table each named 'valid' and 'invalid'

but I do not know how to split the csv file and save them as a psql table through Nifi.

Can anyone help?

2 Answers

What you could do is use a RouteOnContent with the "Content Must Contain Match" factor, with the match being null. Therefore, anything that matches null would be routed that way, and anything not matching null would be routed a different way. Not sure if it's possible the way you're doing it, but that is 1 possibility. The match could be something like (.*?)null

I used QueryRecord processor with two SQL statements each sorting out the rows with null value and the other without the null value and it worked as intended!

Related