我有以下情况。 在第一个流文件中,我有:
id,name,sms,call
1,sachith,,07121
2,nalaka,039444,
3,john,04954,
4,malcom,,69595
然后,我使用sms
处理器将call
和operator
列合并为一个名为UpdateRecord
的新列。 Inspired from this answer
Replacement Value Strategy Record Path Value
/operator concat(/sms, ',', /call)
新流程文件是:
id,name,sms,call,operator
1,sachith,,07121,"null,07121"
2,nalaka,039444,,"039444,null"
3,john,04954,,"04954,null"
4,malcom,,69595,"null,,69595"
在下一个UpdateRecord
处理器中,我尝试删除此null
并将其设为单个值。为此,我使用(需要修改):
Replacement Value Strategy Literal Value
/operator ${field.value:replaceFirst('null',${field.value:substringBefore(',')})}
此输出为:
id,name,sms,call,operator
1,sachith,,07121,"null,07121"
2,nalaka,039444,,"039444,039444"
3,john,04954,,"04954,04954"
4,malcom,,69595,"null,69595"
我想做的就是简单地删除所有null
并替换为number
id,name,sms,call,operator
1,sachith,,07121,07121
2,nalaka,039444,,039444
3,john,04954,,04954
4,malcom,,69595,69595"
除了UpdateRecord
之外,我还必须使用其他处理器吗?
答案 0 :(得分:2)
这是使用UpdateRecord
处理器的方式,其中有选项,
Record Reader CSVReader
Record Writer CSVRecordSetWriter
Replacement Value Strategy Record Path Value
/operator concat(/sms[isEmpty(/call)], /call[isEmpty(/sms)])
这将为您提供如下结果:
id,name,sms,call,operator
1,sachith,,07121,07121
2,nalaka,039444,,039444
3,john,04954,,04954
4,malcom,,69595,69595
如果两者都不为空,则将它们连接起来;如果两者都不为空,则结果也将为null。