You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何编写包含数组的数组字段的Avro Schema?

Avro二维数组字段Schema修正方案

问题根源

当前写法的核心错误有两处:

  1. 内层数组的类型定义多套了一层多余的type对象包装
  2. default配置的层级不符合Avro语法规范

修正后完整Schema

{
    "name": "SelfHealingStarter",
    "namespace": "SCP.Kafka.AvroSchemas",
    "doc": "Message with all the necessary information to run Self Healing process.",
    "type": "record",
    "fields": [
        {
            "name": "FiveMinutesAgoMeasurement",
            "type": "record",
            "doc": "Field with all five minutes ago measurement.",
            "fields": [
                {
                    "name": "equipments",
                    "doc": "List with all equipments measurement, each entry corresponds to a string array of single equipment measurement data.",
                    "type": {
                        "type": "array",
                        "items": {
                            "type": "array",
                            "items": "string",
                            "default": []
                        }
                    },
                    "default": []
                }
            ]
        }
    ]
}

核心调整说明

  • 移除了内层数组外多余的type嵌套:外层数组的items属性直接接收内层数组的类型定义即可,不需要额外包裹{"type": XXX}结构
  • 内层数组的default配置放在内层数组类型定义的同级,符合Avro类型属性的语法要求
  • 修正后Schema对应的数据结构为二维字符串数组,可完美匹配「数组的数组」的需求,两层default配置分别对应外层数组为空、内层子数组为空的默认 fallback 值

内容的提问来源于stack exchange,提问作者Felipe Thomazi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 19:48:03