Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting a json array in a single flowfile based on a Json attribute : Apache Nifi

Tags:

apache-nifi

I have been trying nifi and wanted to know how to sort an array of json by an attribute. I have Json like this

[{“name”:”Backham”,”createdDate”:”2018-05-07 06:30:09”},{“name”:”Rooney”,”createdDate”:”2016-05-12 19:50:03”},{“name”:”Ronaldo”,”createdDate”:”2019-01-07 06:30:09”}]

I have to sort by createdDate asc/desc.

I know that I can write a custom processor to sort the data and send it back. Is there any other better way of doing this? Can anyone please tell me how to accomplish this?

like image 969
15R6 Avatar asked Apr 22 '26 11:04

15R6


1 Answers

You can use Query record processor in NiFi. Configure and enable the Record Reader/Writer controller services(JsonPath Reader/JsonSetWriter).

Add new property in Query Record processor as

OrderbyCreatedDate

SELECT * from FLOWFILE Order By createdDate DESC

Now queryrecord processor will execute above SQL staetment on the flowfile content and gives output flowfile with sorted order based on createddate field.

Use the OrderbyCreatedDate relation from QueryRecord processor for further processing.

For more details regarding configuring/usage of Queryrecord processor refer to this link.

like image 172
notNull Avatar answered Apr 24 '26 08:04

notNull