Apache kafka NiFi:将嵌套JSON文件转换为CSV
我是Nifi的新手,就我而言,我必须使用来自Kafka的JSON主题 我想把它转换成一个CSV文件,我只需要选择几个标量和一些嵌套字段 我需要做以下几件事:Apache kafka NiFi:将嵌套JSON文件转换为CSV,apache-kafka,apache-nifi,Apache Kafka,Apache Nifi,我是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 请点击以下链接: 但不确定这是否是正确的方法,也不知道如何
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
请点击以下链接:
但不确定这是否是正确的方法,也不知道如何创建单个文件。
Im使用NiFi(1.8),模式存储在汇合模式注册表中
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" : ""
} ]
}
请指导我。使用JsonTreeReader和CSVRecordSetWriter尝试ConvertRecord。编写器可以配置为包含标题行,而不需要拆分/合并。UpdateAttribute可用于设置
filename
属性,该属性是流文件的关联文件名(例如,由PutFile使用)
如果ConvertRecord没有提供您想要的输出,请详细说明它提供的内容与您期望的内容之间的区别。请使用JsonTreeReader和CSVRecordSetWriter尝试ConvertRecord。编写器可以配置为包含标题行,而不需要拆分/合并。UpdateAttribute可用于设置
filename
属性,该属性是流文件的关联文件名(例如,由PutFile使用)
如果ConvertRecord没有提供您想要的输出,您能否详细说明它提供的内容与您期望的内容之间的区别?JSON是什么样子的,以及您打算如何将嵌套字段表示为CSV值?我已经更新了示例JSON。嵌套字段应作为csv文件中的单个记录进入。JSON看起来像什么,您打算如何将嵌套字段表示为csv值?我已更新了示例JSON。嵌套字段应作为csv文件中的单个记录进入。