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

ぃ、小莉子 提交于 2019-12-23 02:02:03

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/50311233/sorting-a-json-array-in-a-single-flowfile-based-on-a-json-attribute-apache-nif

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!