在 NIFI 中,如何在没有 CSV 标头的情况下从 CSV 转换为 JSON。对于每个 CSV 行 searate json 流文件应该创建并发送到下一个处理器。下面是csv
861359032561480,1,15.480237,190506144035,a
861359032561480,3,16.480237,190506144035,b
861359032561480,2,17.480237,190506144035,c
预期的 json 是:
{"test":861359032561480,"test2":"1","test3":15.48,"test4":190506144035,"test5":A}
在上面的 JSON 中,第二个 json 值 1 是字符串,在第三个 json 值中,该值限制为小数点后 2 位,第四个 json 值中大写。
那么,我该如何转换和应用这些转换呢?
使用QueryRecord
(将字段转换为大写)处理器然后Split the array of json
记录。
配置Record Reader(CSVReader)/Writer(JsonRecordSetWriter)
.
在JsonSetWriter
保持匹配的Avro模式类似long,string,decimal
。
在QueryRecord处理器中添加新属性并保留 sql 语句以UPPER(test5)
使用ApacheCalcite sql 解析器将“test5”转换为case 。
您的 sql 语句将类似于以下内容..
select test,test2,test3,test4,UPPER(test5)test5 from flowfile
然后使用SplitRecord(prefered if json file is big)
(或)SplitJson处理器将 json 记录数组拆分为单个流文件。
流:
1.QueryRecord //to read csv and write in json format
2.SplitRecord (or) SplitJson //to Split array into individual flowfiles
3.other processors.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句