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

查看:39
本文介绍了使用 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_salaryallowance 一起添加并使其成为 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?

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

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天全站免登陆