给定以下 CSV 输入文件:
name,amount
Abc,"1,234.56"
Def,"2,222,222.222222"
Run Code Online (Sandbox Code Playgroud)
金额字段包含带逗号的十进制数。NiFi中如何将其解析为数字?我不想将其解析为字符串。
我想过使用UpdateRecord处理器、表达式语言和Java的NumberFormat来解析它,但似乎NumberFormat无法从表达式语言访问。或者,我想使用 ScriptedRecordSetWriter 进行解析,但找不到任何工作示例。
感谢任何帮助,尤其是工作示例。
When we are reading the incoming data we still needs to use String type(as the data is enclosed in ")
while writing out the data from UpdateRecord processor we can use int/decimal
types to write the output flowfile records.
1. Using Record Path Value:
You can read the incoming data as String datatype, Output flowfile will have integer type defined() and using UpdateRecord processor replace the ',' with ''
Add new property in UpdateRecord processor as
/amount
substringBefore(replace(/amount,',',''),'.')
Run Code Online (Sandbox Code Playgroud)
Now the output flowfile will have integer datatype for the amount field.
2. Using Literal Value:
If we are using literal value we can use NiFi expression language functions on field.value by using replace
and toNumber
functions we are able to get int value for amount field.
Both ways we are going to get output flowfile in json format as
[{"name":"Abc","amount":1234},{"name":"Def","amount":2222222}]
Run Code Online (Sandbox Code Playgroud)
In the same way if you want to have decimal as output flowfile type define avro schema with decimal type and don't use substringBefore and toNumber functions.
归档时间: |
|
查看次数: |
4903 次 |
最近记录: |