【问题标题】:How to write a JSON into a Avro Schema in NiFi如何在 NiFi 中将 JSON 写入 Avro Schema
【发布时间】:2020-11-18 21:52:06
【问题描述】:

我想编写一个 Avro 架构。 JSON是这样的。

{
"manager": {
    "employeeId": "ref-456",
    "name": "John Doe"
  }
}

这是我编写的架构。但这是错误的。我怎样才能把它改成正确的?

{
    "namespace":"nifi",
    "name":"store_event",
    "type":"record",
    "fields":[ {
        "name" : "manager",
        "type" : [
            {"name":"employeeId", "type":"string"},
            {"name":"name", "type":"string"}
        ]   
    }       
        
    ]
}

【问题讨论】:

    标签: json apache-nifi avro


    【解决方案1】:

    这里是:

        {
        "type": "record",
        "name": "nifiRecord",
        "namespace": "org.apache.nifi",
        "fields": [
            {
                "name": "manager",
                "type": [
                    "null",
                    {
                        "type": "record",
                        "name": "managerType",
                        "fields": [
                            {
                                "name": "employeeId",
                                "type": [
                                    "null",
                                    "string"
                                ]
                            },
                            {
                                "name": "name",
                                "type": [
                                    "null",
                                    "string"
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    }
    

    您实际上可以很容易地推断出架构(我使用您的 json 有效负载进行了此操作)

    将 ConvertRecord 与 JsonTreeReader(推断架构)+ JsonTreeSetWritter(设置 Avro.Schema 属性 - 这将告诉您架构)一起使用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-19
      • 1970-01-01
      • 1970-01-01
      • 2020-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多