【问题标题】:Avro schema - map type as optional fieldAvro 模式 - 映射类型作为可选字段
【发布时间】:2020-07-17 07:44:03
【问题描述】:

如何将 avro 模式中的 arrayofmap 设置为可选字段。以下模式正在运行,但是,如果数据中缺少此字段,则解析失败,org.apache.avro.AvroTypeException: Error converting field - quantities and.Caused by: org.apache.avro.AvroTypeException: Expected array-start. Got VALUE_NULL ` 我只是想确保数据的反序列化通过该字段是否存在于数据中。

{
         "name":"quantities",
         "type":{
            "items":{
               "type":"map",
               "values":"string"
            },
            "type":"array"
         },
         "default" : null,
      }

【问题讨论】:

  • 自己刚刚找到了解决方案。这将使地图字段数组在 avro 架构中成为可选的 ``` { "name": "quantities", "type": ["null", { "type": "array", "items": { "type ": "map", "values": "string" } } ], "default": null, } ```

标签: avro


【解决方案1】:

我自己刚刚找到了解决方案。这将使映射字段数组在 avro 架构中成为可选

{
         "name": "quantities",
         "type": ["null",
             {
                 "type": "array",
                 "items": {
                  "type": "map",
                     "values": "string"
                 }
             }
         ],
         "default": null,
      }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-02
    • 2018-11-23
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多