且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用apache nifi使用预定义文件将列添加到csv

更新时间:2023-12-01 11:40:34

使用

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](?!,)

Debuggex演示

结果: