Skip to main content
joaoluistr
Gold ⭐️
Dec 17, 2020 7:31 PM UTC
Solved

Nifi CSV rows processing to sql server - Check primary key

Hello Community!

Hope you're all doing fine.

 

I'm beggining my Nifi studying and i'de like to replicate a process that i have running in other plataforms.

My goal is to read a CSV and process it row by row to insert into a sql server table.

 

So far so good, i was able to do this with the following:

 

GetFile -> SplitRecord -> ConvertRecord (to json) -> ConvertJSONtoSQL -> UpdateAttribute (date conversion) -> PutSQL.

 

But i need to validade if the record already exists in the destiny table. Can anyone help me with that? Already looked for but i wasn't able to find somethig like it.

 

If you guys have a solution that is better and completely different, no problem, i'm open to any change.

 

Thanks in advance!

joaoluistr
Gold ⭐️
Dec 29, 2020 3:53 PM UTC

Hello everyone!

 

I'm here to post the solution i was able to develop to solve my problem.

 

I managed to do the following:

 

GetFile -> SplitRecord (converting to JSON) -> EvaluateJsonPath (to get key columns) -> ExecuteSQL (select with keys to check if exists) -> RouteOnAttribute (to execute update or insert depending on select result) -> ExecuteSQL (It can be update or insert).

 

Capturar.PNG

4 replies

joaoluistr
joaoluistrAuthorAnswer
Gold ⭐️
Dec 29, 2020 3:53 PM UTC

Hello everyone!

 

I'm here to post the solution i was able to develop to solve my problem.

 

I managed to do the following:

 

GetFile -> SplitRecord (converting to JSON) -> EvaluateJsonPath (to get key columns) -> ExecuteSQL (select with keys to check if exists) -> RouteOnAttribute (to execute update or insert depending on select result) -> ExecuteSQL (It can be update or insert).

 

Capturar.PNG

Translate
TimothySpann
Platinum ⭐️⭐️⭐️
Platinum ⭐️⭐️⭐️
Jan 5, 2021 9:28 PM UTC

executesqlrecord or putdatabaserecord may be easier.

Translate
joaoluistr
Gold ⭐️
Jan 11, 2021 2:06 PM UTC

Hello Timothy!

 

Could you elaborate, please?

Translate