问题描述
我一直在尝试 nifi 并想知道如何按属性对 json 数组进行排序.我有这样的 Json
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-1219:50:03"},{name":"Ronaldo","createdDate":"2019-01-07 06:30:09"}]
[{"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"}]
我必须按 createdDate asc/desc 排序.
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?
推荐答案
您可以在 NiFi 中使用查询记录处理器.配置并启用 Record Reader/Writer 控制器服务(JsonPath Reader/JsonSetWriter).
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
现在查询记录处理器将对流文件内容执行上述SQL语句,并根据createddate字段提供具有排序顺序的输出流文件.
Now queryrecord processor will execute above SQL staetment on the flowfile content and gives output flowfile with sorted order based on createddate field.
使用来自 QueryRecord 处理器的 OrderbyCreatedDate 关系进行进一步处理.
Use the OrderbyCreatedDate relation from QueryRecord processor for further processing.
有关配置/使用 Queryrecord 处理器的更多详细信息,请参阅 这个链接.
For more details regarding configuring/usage of Queryrecord processor refer to thislink.
这篇关于基于 Json 属性在单个流文件中对 json 数组进行排序:Apache Nifi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!