我是Nifi的新手,我不得不使用Kafka的JSON主题 并希望将其转换为CSV文件,我只需要选择几个标量和一些嵌套字段即可。
我需要做以下事情:
Consume topic - Done
Json to CSV
Include header in the CSV file
Merge into single file (if its split)
Give a proper filename with date
下面的链接: https://community.hortonworks.com/articles/64069/converting-a-large-json-file-into-csv.html
但是不确定这是否是正确的方法,也不知道如何制作单个文件。
我正在使用NiFi (1.8) and schema is stored in Confluent Schema Registry
Json示例:
{
"type" : "record",
"name" : "Customer",
"namespace" : "namespace1"
"fields" : [ {
"name" : "header",
"type" : {
"type" : "record",
"name" : "CustomerDetails",
"namespace" : "namespace1"
"fields" : [ {
"name" : "Id",
"type" : "string"
}, {
"name" : "name",
"type" : "string"
}, {
"name" : "age",
"type" : [ "null", "int" ],
"default" : null
}, {
"name" : "comm",
"type" : [ "null", "int" ],
"default" : null
} ]
},
"doc" : ""
}, {
"name" : "data",
"type" : {
"type" : "record",
"name" : "CustomerData"
"fields" : [ {
"name" : "tags",
"type" : {
"type" : "map",
"values" : "string"
}
}, {
"name" : "data",
"type" : [ "null", "bytes" ]
"default" : null
} ]
},
"doc" : ""
} ]
}
请指导我。
答案 0 :(得分:0)
尝试使用JsonTreeReader和CSVRecordSetWriter进行ConvertRecord。可以将编写器配置为包括标题行,并且您无需拆分/合并。 UpdateAttribute可用于设置filename
属性,该属性是流文件的关联文件名(例如,由PutFile使用)。
如果ConvertRecord没有给您想要的输出,您能否详细说明一下它给您的输出与您期望的输出之间的区别?