apache-nifi - Nifi从数据库添加属性
问题描述
我目前正在 Nifi 中从 FTP 获取文件,但在获取文件之前我必须检查一些条件。场景是这样的。
列出 FTP -> 检查条件 -> 获取 FTP
在检查条件部分,我从数据库中获取了一些值并与文件名进行比较。那么我可以使用更新属性从数据库中获取一些记录并使其成为这样吗?
列出 FTP -> 更新属性(来自 DB)-> 属性路由 -> 获取 FTP
解决方案
我认为您的流程如下所示
流动:
1.ListFTP //to list the files
2.ExecuteSQL //to execute query in db(sample query:select max(timestamp) db_time from table)
3.ConvertAvroToJson //convert the result of executesql to json format
4.EvaluateJsonPath //keep destination as FlowfileAttribute and add new property as db_time as $.db_time
5.ROuteOnAttribute //perform check filename timestamp vs extracted timestamp by using nifi expresson language
6.FetchFile //if condition is true then fetch the file
RouteOnAttribute 配置:
我假设文件名类似于fn_2017-08-2012:09:10并且 executesql 已返回2017-08-2012:08:10
表达:
${filename:substringAfter('_'):toDate("yyyy-MM-ddHH:mm:ss"):toNumber()
:gt(${db_time:toDate("yyyy-MM-ddHH:mm:ss"):toNumber()})}
通过使用上面的表达式,我们使用处理器添加了filename value same as ListFTP
文件名和db_time
属性EvaluateJsonPath
,我们将时间戳更改为数字,然后进行比较。
有关 NiFi 表达语言的更多详细信息,请参阅此链接。
推荐阅读
- javascript - 如何在 HTML、CSS、JS 的响应式导航栏中更改活动选项卡?
- python-3.x - 如何在烧瓶中显示 pydotplus 图
- reactjs - NextJS 在第一个请求中不返回整个页面内容
- r - R4.1 中的管道运算符
- flutter - 这里不允许使用属性 android:usesCleartextTraffic
- python - 在非标记数据集上使用 MLP 进行聚类
- javascript - 如何在 onSubmit 上设置条件
- reactjs - 在组件页面中隐藏一个组件并显示另一个组件 - react js
- math - 一个数字 N 和一个数字 P 。你的任务是找出从 1 到 N(含)范围内没有数字 P 的数字的数量
- typescript - 导出的变量“Foo”在打字稿中已经或正在使用私有名称“ParentChild”