【问题标题】:Avro schema for record type with empty object具有空对象的记录类型的 Avro 模式
【发布时间】:2019-09-17 13:33:02
【问题描述】:

我正在尝试为下面的 json 创建 avro 架构

  {
  "id": "TEST",
  "status": "status",
  "timestamp": "2019-01-01T00:00:22-03:00",
  "comment":  "add comments or replace it with adSummary data",
  "error": { 
    "code": "ER1212132",
    "msg": "error message"
  }
}

错误对象是可选的,它可以是 “错误” :{} 下面是没有默认值的avro架构

{
  "type" : "record",
  "name" : "Order",
  "fields" : [ {
    "name" : "id",
    "type" : "string"
  }, {
    "name" : "status",
    "type" : "string"
  }, {
    "name" : "timestamp",
    "type" : "string"
  }, {
    "name" : "comment",
    "type" :  ["null","string"],
    "default": null
  }, {
    "name" : "error",
    "type" : {
      "type" : "record",
      "name" : "error",
      "fields" : [ {
        "name" : "code",
        "type" : "string"
      }, {
        "name" : "msg",
        "type" : "string"
      } ]
    }
  } ]
}

如何为 json 中的错误字段添加默认值 {}。

【问题讨论】:

    标签: avro spark-avro avro-tools


    【解决方案1】:

    {
      "type" : "record",
      "name" : "Order",
      "fields" : [ {
        "name" : "id",
        "type" : "string"
      }, {
        "name" : "status",
        "type" : "string"
      }, {
        "name" : "timestamp",
        "type" : "string"
      }, {
        "name" : "comment",
        "type" :  ["null","string"],
        "default": null
      }, {
        "name" : "error",
        "type" : [{"type": "record", "fields":[{"name": "code", "type":"string"}, {"name": "msg", "type":"string"}]}, {"type": "record", "fields":[]}]
      
      } ]
    }

    【讨论】:

      猜你喜欢
      • 2020-07-08
      • 1970-01-01
      • 1970-01-01
      • 2020-07-03
      • 1970-01-01
      • 1970-01-01
      • 2020-07-20
      • 2018-06-14
      • 2020-10-29
      相关资源
      最近更新 更多