null - Avro模式。如何一次将类型设置为 "record"和 "null"

标签 null schema union record avro

我需要在架构中将“记录”类型与空类型混合使用。

"name":"specShape",
         "type":{
            "type":"record",
            "name":"noSpecShape",
            "fields":[
               {
                  "name":"bpSsc",
                  "type":"null",
                  "default":null,
                  "doc":"SampleValue: null"
               },...

例如,对于某些数据,specShape可以为null。

因此,如果我将类型设置为
"name":"specShape",
         "type":{
            **"type":["record", "null"],**
            "name":"noSpecShape",
            "fields":[
               {
                  "name":"bpSsc",
                  "type":"null",
                  "default":null,
                  "doc":"SampleValue: null"
               },...

它说
No type: {"type":["record","null"]...

但是如果我将whoole类型设置为
"name":"specShape",
         **"type":[{
            "type":"record",
            "name":"noSpecShape",
            "fields":[
               {
                  "name":"bpSsc",
                  "type":"null",
                  "default":null,
                  "doc":"SampleValue: null"
               }, "null"]**,...

它说
Not in union [{"type":"record"

如何结合这两种类型?

最佳答案

您有一个正确的想法,您只需要在更高级别的"null"数组中包括"type"即可,而不是在"fields"数组内部即可(如您的第三个示例)。这是可为空的记录的架构:

[
  "null",
  {
    "type": "record",
    "name": "NoSpecShape",
    "fields": [
      {
        "type": "null",
        "name": "bpSsc",
        "default": null
      }
    ]
  }
]

您还可以将其嵌套在需要进行类型声明的任何位置,例如在另一个记录中:
{
  "type": "record",
  "name": "SpecShape",
  "fields": [
    {
      "type": [
        "null",
        {
          "type": "record",
          "name": "NoSpecShape",
          "fields": [
            {
              "type": "null",
              "name": "bpSsc",
              "default": null
            }
          ]
        }
      ],
      "name": "shape"
    }
  ]
}

最后一个模式的JSON编码实例如下所示:
  • {"shape": null}
  • {"shape": {"NoSpecShape": {"bpSsc": null}}}
  • 关于null - Avro模式。如何一次将类型设置为 "record"和 "null",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36321616/

    相关文章:

    c++ - 用于 C++ 的 MySQL 连接器 | setSchema 上的 MySQL_Connection::setReadOnly() 异常

    javascript - Business Catalyst - 如何从架构元内容中删除井号

    xml - 是否可以使用 xs :union for complexTypes?

    mysql - 创建 View 连接两个具有相同列且没有重复的表

    mysql - 如果日期列中的值存在于所有 3 个表中,则合并 3 个结构相同的表

    MySQL 无法选择特定字段值?

    MySQL GROUP BY NULL 和 EMPTY

    mysql - 数据库架构中的文件夹

    java - 方法结束后向 HashMap 添加的条目将变为 null

    javascript - 当 JavaScript 返回 null & undefined 时?