使用 NIFI 如何将属性应用到来自 json 文件的 zip 中的文件也包含在同一 zip 中?
Using NIFI how do you apply attributes to files in a zip from a json file also contained in the same zip?
我想使用 Apache Nifi 处理一个包含 category.json 文件和多个数据文件的 zip,如图所示。
somefile.zip
├──category.json
├──datafile-1
├──datafile-2
├──...
├──datafile-n
示例category.json
{
"category": "history",
"rating" : 5
}
我想做的是解压缩文件并将 category.json 数据作为属性应用到每个数据文件。
处理这个问题的最佳方法是什么?
Myabe 不是最好的,但它是一种方法:
1) 解压缩
2) 基于 category.json 文件名
使用 routeOnAttribut
3) 在 category.json flowfile
中检索类别作为属性
4) 再次压缩所有文件但保留 atttribut
5) 再次解压并保留属性,您所有的流文件将具有类别属性
我建议从 ListFile
和 FetchFile
(或 GetFile
本身)的组合开始检索存档,CompressContent
to extract the component files, RouteOnAttribute
using the flowfile filename attribute to separate the flowfile containing category.json
, and the EvaluateJSONPath
处理器检索JSON 该流文件的内容并将某些值填充到属性中。
从那里开始,不清楚您的问题是如何更新包含该存档中数据文件之一的每个流文件的 NiFi 流文件属性,还是将提取的 JSON 应用于磁盘上某处的数据文件.
假设是前者,您可以将提取的 JSON 写入变量或参数(使用 ExecuteScript
to do so) and use UpdateAttribute
将这些属性应用于 CompressContent
处理器产生的其他流文件。
我想使用 Apache Nifi 处理一个包含 category.json 文件和多个数据文件的 zip,如图所示。
somefile.zip
├──category.json
├──datafile-1
├──datafile-2
├──...
├──datafile-n
示例category.json
{
"category": "history",
"rating" : 5
}
我想做的是解压缩文件并将 category.json 数据作为属性应用到每个数据文件。
处理这个问题的最佳方法是什么?
Myabe 不是最好的,但它是一种方法:
1) 解压缩
2) 基于 category.json 文件名
使用 routeOnAttribut
3) 在 category.json flowfile
中检索类别作为属性
4) 再次压缩所有文件但保留 atttribut
5) 再次解压并保留属性,您所有的流文件将具有类别属性
我建议从 ListFile
和 FetchFile
(或 GetFile
本身)的组合开始检索存档,CompressContent
to extract the component files, RouteOnAttribute
using the flowfile filename attribute to separate the flowfile containing category.json
, and the EvaluateJSONPath
处理器检索JSON 该流文件的内容并将某些值填充到属性中。
从那里开始,不清楚您的问题是如何更新包含该存档中数据文件之一的每个流文件的 NiFi 流文件属性,还是将提取的 JSON 应用于磁盘上某处的数据文件.
假设是前者,您可以将提取的 JSON 写入变量或参数(使用 ExecuteScript
to do so) and use UpdateAttribute
将这些属性应用于 CompressContent
处理器产生的其他流文件。