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

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

PubSub Avro schema with JSON array throws Invalid schema definition error

问题

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

  1. {
  2. ...
  3. "Tags": ["2333TAG"],
  4. ...
  5. }

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

  1. {
  2. "type": "record",
  3. "name": "Avro",
  4. "fields": [
  5. ...
  6. {
  7. "name": "Tags",
  8. "type": "array",
  9. "items": "string",
  10. "default": []
  11. },
  12. ...
  13. ]
  14. }

但是当我尝试验证定义时,我收到错误消息:无效的模式定义:引用节点未引用先前声明的类型: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:

  1. {
  2. ...
  3. "Tags": ["2333TAG"],
  4. ...
  5. }

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

  1. {
  2. "type": "record",
  3. "name": "Avro",
  4. "fields": [
  5. ...
  6. {
  7. "name": "Tags",
  8. "type": "array",
  9. "items": "string",
  10. "default": []
  11. },
  12. ...
  13. ]
  14. }

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

  1. {
  2. "type": "record",
  3. "name": "Avro",
  4. "fields": [
  5. ...
  6. {
  7. "name": "Tags",
  8. "type": {
  9. "type": "array",
  10. "items": "string",
  11. "default": []
  12. }
  13. }
  14. ...
  15. ]
  16. }
英文:

Avro requires a nested type for declaring an array:

  1. {
  2. "type": "record",
  3. "name": "Avro",
  4. "fields": [
  5. ...
  6. {
  7. "name": "Tags",
  8. "type": {
  9. "type": "array",
  10. "items": "string",
  11. "default": []
  12. }
  13. }
  14. ...
  15. ]
  16. }

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:

确定