问题描述
我得到一个原始的csv文件,看起来像这样
I get a raw csv file which looks like this
id,name,star
1,sachith,2
2,nalaka,1
3,abc,3
我想将星号列与另一个具有该文件的文件映射
I want to map star column with another file where it has
1 1S
2 3S
3 5S
最后csv应该看起来像
and finally csv should look like
id,name,star,level
1,sachith,2,3S
2,nalaka,1,1S
3,abc,3,5S
我使用了 ReplaceTextWithMapping ,但它替换了包括id列在内的所有1,2,3值.
I have used ReplaceTextWithMapping, but it replaces all the 1,2,3 values including in id column.
此处替换一个值,但是我想映射一个新列并将其添加到记录中.
Here it defines replacing a value, but I want to map and add a new column to the record.
在@Upvote回答之后.我的ReplaceTextWithMapping conf
After @Upvote's answer. My ReplaceTextWithMapping conf
推荐答案
使用 ReplaceTextWithMapping .总体流量:
Use ReplaceTextWithMapping. Overall flow:
GenerateFlowFile:
GenerateFlowFile:
UpdateRecord:
UpdateRecord:
配置CSVReader
将第一行视为标题.保持其他属性不变.将CSVRecordSetWrite
配置为将第一行视为标头,从架构文本属性派生的架构,并将架构文本设置为:
Configure CSVReader
to treat first line as header. Leave other properties untouched. Configure CSVRecordSetWrite
to treat first line as header, schema to be derived from schema text property and set schema text to:
{
"type":"record",
"name":"foobar",
"namespace":"my.example",
"fields":[
{
"name":"name",
"type":"string"
},
{
"name":"age",
"type":"int"
},
{
"name":"id",
"type":"string"
},
{
"name":"nick",
"type":"string"
}
]
}
请注意,它包括新列. ReplaceTextWithMapping:
Notice that it includes the new column. ReplaceTextWithMapping:
映射文件内容:
1 1S
2 3S
3 4S
值由制表符分隔.正则表达式必须与最后一个值匹配,且每行中都不能跟逗号:
Values are separated by tab. Regex must match the last value not followed by a comma in each line:
[0-9](?!,)
结果:
这篇关于使用apache nifi使用预定义文件将列添加到csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!