首页 > 解决方案 > 定义 Avro 模式

问题描述

我有一些像这样的 avro 数据,它们打印在终端中。

{"cust_status_id":0, "cust_status_description":{"string":" Approved"}}

我创建的 avro 模式就像

{
  "namespace": "com.thp.report.model",
  "type": "record",
  "name": "PraStatusMaster",
  "fields": [
    {
      "name": "cust_status_id",
      "type": "int"
    },
    {
      "name": "cust_status_description",
      "type": "string",
      "avro.java.string": "String"
    }
  ]
}

架构是否正确?

标签: avro

解决方案


您的 json 的正确架构如下:

{
  "name": "PraStatusMaster",
  "type": "record",
  "namespace": "com.thp.report.model",
  "fields": [
    {
      "name": "cust_status_id",
      "type": "int"
    },
    {
      "name": "cust_status_description",
      "type": {
        "name": "cust_status_description",
        "type": "record",
        "fields": [
          {
            "name": "string",
            "type": "string"
          }
        ]
      }
    }
  ]
}

推荐阅读