PubSub Avro架构中的JSON数组引发了无效的架构定义错误。

huangapple go评论51阅读模式
英文:

PubSub Avro schema with JSON array throws Invalid schema definition error

问题

我正在设置一个发布/订阅主题来接收一些JSON数据。JSON数据中的一个字段是一个字符串数组,如下所示:

{
    ...
    "Tags": ["2333TAG"],
    ...
}

我尝试按照Avro 1.11规范定义模式:

{
  "type": "record",
  "name": "Avro",
  "fields": [
    ...
    {
      "name": "Tags",
      "type": "array",
      "items": "string",
      "default": []
    },
    ...
  ]
}

但是当我尝试验证定义时,我收到错误消息:无效的模式定义:引用节点未引用先前声明的类型:array

你知道我可能做错了什么吗?我已经确认这是模式中引发错误的字段。

英文:

I'm setting up a pub/sub topic to receive some JSON data. One of the fields in the JSON data is an array of strings, like so:

{
    ...
    "Tags": ["2333TAG"],
    ...
}

I've tried defining the schema as per the Avro 1.11 spec:

{
  "type": "record",
  "name": "Avro",
  "fields": [
    ...
    {
      "name": "Tags",
      "type": "array",
      "items": "string",
      "default": []
    },
    ...
  ]
}

But when I try to validate the definition, I get the error: Invalid schema definition: Reference node does not refer to previously declared type: array

Any idea of what I might be doing wrong? I have verified that this is the field in the schema that's throwing the error.

答案1

得分: 2

Avro 需要使用嵌套类型来声明一个 array

{
  "type": "record",
  "name": "Avro",
  "fields": [
    ...
    {
      "name": "Tags",
      "type": {
        "type": "array",
        "items": "string",
        "default": []
      }
    }
    ...
  ]
}
英文:

Avro requires a nested type for declaring an array:

{
  "type": "record",
  "name": "Avro",
  "fields": [
    ...
    {
      "name": "Tags",
      "type": {
        "type": "array",
        "items": "string",
        "default": []
      }
    }
    ...
  ]
}

huangapple
  • 本文由 发表于 2023年7月10日 21:27:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76654227.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定