使用apache-nifi将两列加在一起 [英] Add two columns together using apache-nifi

查看:115
本文介绍了使用apache-nifi将两列加在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情况。我有一个数据库表:

I have following scenario. I one database table I have :

| id | name | basic_salary | allowance |
_______________________________________|
| 1  | sach | 2000         | 1000      |
| 2  | nala | 5000         | 2500      |
|______________________________________|

添加 basic_salary allow 并使其成为 net_salary ,然后插入到名为 net_salary

add basic_salary and allowance togther and making it as net_salary and insert to a new table called net_salary

第一步,我使用了 ExecuteSQLRecord 处理器,可以获取所有记录。但是问题是:如何添加流文件中的这两列。

For first step, I used ExecuteSQLRecord processor and can get all the records. But problem is : How to add those two columns coming in flowfile.

所以最终结果应该是:

| id | name | net_salary |
|________________________|
| 1  | sach | 3000       |
| 2  | nala | 7500       |

这直接与我之前的变量问题
如何处理流文件变量以在 apache-nifi 中执行操作?

This is directly related to my previous variable question. How to handle flowfile variables to perform operations in apache-nifi?

我使用了如何计算PostgreSQL中多个列的总和 ExecuteSQL 处理器,但无法理解流文件变量。

I used How to compute the sum of multiple columns in PostgreSQL inside ExecuteSQL processor, but it can not understand flowfile variables.

推荐答案

有是一个棘手的问题。使用两次 UpdateRecord

There is a tricky one. Use UpdateRecord twice.

第一个是

Record Reader               CSVReader
Record Writer               CSVRecordSetWriter
Replacement Value Strategy  Record Path Value
/net_salary                 concat(/basic_salary, ',', /allowance)

第二个是

Record Reader               CSVReader
Record Writer               CSVRecordSetWriter
Replacement Value Strategy  Literal Value
/net_salary                 ${field.value:substringBefore(','):toNumber():plus(${field.value:substringAfter(','):toNumber()})}

给出结果如下。

id,name,basic_salary,allowance,net_salary
1,sach,2000,1000,3000
2,nala,5000,2500,7500

这篇关于使用apache-nifi将两列加在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆