【问题标题】:Avro Schema failureAvro 架构失败
【发布时间】:2017-12-15 12:01:38
【问题描述】:

我有以下对象:

[
{"ProductId":10,"ProductName":"some name"}
]

但有时我只有null。我正在尝试为此提出一个架构。但这似乎不起作用:(。

我尝试了以下两种:

{
    "name": "ProductsOrNull", 
    "type": ["null", {
      "type": "array",
      "name": "Products",
      "items": {
        "type":"record",
        "name": "Product",
        "fields": [{
            "name":"ProductId",
            "type":"long"
          }, {
            "name":"ProductName",
            "type":"string"
          }
        ]
      }
    }],
    "default": null
}

但是在运行java -jar avro-tools-1.8.2.jar fromjson --schema-file prod.avsc prod.json > lol.avro 时它会以Exception in thread "main" org.apache.avro.SchemaParseException: No type: <...> 失败。

我也尝试过同样的错误:

{
  "type": ["null", "array"],
  "name": "Products",
  "items": {
    "type":"record",
    "name": "Product",
    "namespace": "{{ dataModelSchema }}",
    "fields": [{
        "name":"ProductId",
        "type":"long"
      }, {
        "name":"ProductName",
        "type":"string"
      }
    ]
  }
}

我不太明白问题出在哪里,两者有什么区别。

【问题讨论】:

    标签: avro


    【解决方案1】:

    根据您的架构,您的 json 对象应如下所示

    {
    "ProductsOrNull" : 
    [
    {"ProductId":10,"ProductName":"some name"}
    ] 
    }
    

    没有办法用没有字段名的数组来定义和 avro 模式。

    【讨论】:

      猜你喜欢
      • 2020-05-19
      • 2021-02-06
      • 1970-01-01
      • 2018-07-30
      • 2022-01-21
      • 2021-04-01
      • 2020-03-17
      • 2018-12-04
      • 1970-01-01
      相关资源
      最近更新 更多