本文介绍了基于Json属性在单个流文件中对json数组进行排序:Apache Nifi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试nifi,想知道如何通过属性对json数组进行排序.我有这样的杰森

[{"name":"Backham","createdDate":"2018-05-07 06:30:09"},{"name":"Rooney","createdDate":"2016-05-12 19:50:03"},{名称":罗纳尔多","createdDate":"2019-01-07 06:30:09"}]

我必须按createdDate asc/desc排序.

我知道我可以编写一个自定义处理器来对数据进行排序并将其发送回去.还有其他更好的方法吗?谁能告诉我如何做到这一点?

解决方案

您可以在NiFi中使用查询记录处理器.配置并启用Record Reader/Writer控制器服务(JsonPath Reader/JsonSetWriter).

在查询记录处理器中将新属性添加为

OrderbyCreatedDate

SELECT * from FLOWFILE Order By createdDate DESC

现在,queryrecord处理器将对 flowfile内容执行以上SQL步骤,并根据createddate字段为输出流文件提供排序顺序.

使用QueryRecord处理器中的OrderbyCreatedDate关系进行进一步处理.

有关配置/使用Queryrecord处理器的更多详细信息,请参见链接.

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?

解决方案

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 thislink.

这篇关于基于Json属性在单个流文件中对json数组进行排序:Apache Nifi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 18:31