如何在JSON avro模式中创建枚举数组?

owfi6suc  于 2023-08-08  发布在  其他
关注(0)|答案(2)|浏览(85)

我希望有一个avro模式,它有一个名为validExtensions的字段。如何让validExtensions接受枚举扩展列表?
我在枚举中创建了一个可接受的扩展列表:

{
    "type":"enum",
    "name":"extensions",
    "symbols": [".zip",".txt",".csv",".pdf",".xls",".xlsx"]
    }

字符串
但是我似乎找不到一种方法,在扩展中拥有一个接受枚举值数组的字段。例如,json输出如下:

{
 "data":{
    "validExtensions": [".csv", ".xls"],
    "fileName": "testing.csv"
        }
 }


以下是我已经尝试过的,但它不起作用:

{
    "type":"record",
    "name":"data",
    "fields": [
        {
            "name":"validExtensions",
            "type":"array",
            "items": {
                "extensions"
                }
        }
    ]
}

1hdlvixo

1hdlvixo1#

找到了一些与枚举数组一起工作的东西:

{
   "type":"enum",
   "name":"Extensions",
   "symbols": [".zip",".txt",".csv"]
 }

 {
  "type":"record",
  "name":"data",
  "fields": [
    {
        "name": "key",
        "type": "string"
    {
        "name":"validExtensions",
        "type":{"type":"array", "items":"Extensions"}
    }
  ]
}

字符串

ckx4rj1h

ckx4rj1h2#

{
     "type": "record",
     "name": "data",
     "fields": [
        {
         "name": "key",
         "type": "string"
    },
    {
      "name": "validExtensions",
      "type": {
        "type": "array",
        "items": {
          "type": "enum",
          "name": "Extensions",
          "symbols": [
            ".zip",
            ".txt",
            ".csv"
          ]
        }
      }
    }
  ]
}

字符串

相关问题