doukunsan5553 2019-02-14 15:57
浏览 319

无法在Golang中解析AVRO模式

I am having trouble parsing my AVRO json schema. I try to use the avro.ParseSchema function from this library: https://github.com/go-avro/avro. However, i get the following error message:

Unknown type name: array

I've been trying to fix this for a long time but i cannot seem to make it right. I have the following strucs implemented:

import (
   "bytes"
   "log"

   avro "gopkg.in/avro.v0"
)

type Matrix struct {
    UID  int         `avro:"uid"`
    Data [][]float64 `avro:"data"`
}

type MatrixContainer struct {
    MatricesArray []*Matrix `avro:"matrices_array"`
}

//Somewhere in here it goes wrong
 schema, err := avro.ParseSchema(`{
        "type": "record",
        "name": "MatrixContainer",
        "fields": [
            {
                "name": "matrices_array", 
                "type": "array", 
                "items": {
                    "type": "record",
                    "name": "Matrix",
                    "fields": [
                        {"name": "uid","type":"int"},
                        {"name": "data","type":"array","items":
                            {"type":"array","items":"double"}
                        }
                    ]
                }
            }

        ]
    }`)

Any help would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dousi8931 2019-07-22 13:01
    关注

    inside a record field, you can't say "type": "array"; you need to make "type" be a valid avro schema, not a valid avro type.

    Try the following:

    {
        "type": "record",
        "name": "MatrixContainer",
        "fields": [
            {
                "name": "matrices_array",
                "type": {
                    "type": "array",
                    "items": {
                        "type": "record",
                        "name": "Matrix",
                        "fields": [
                            {
                                "name": "uid",
                                "type": "int"
                            },
                            {
                                "name": "data",
                                "type": {
                                    "type": "array",
                                    "items": {
                                        "type": "array",
                                        "items": "double"
                                    }
                                }
                            }
                        ]
                    }
                }
            }
        ]
    }
    

    ref: https://avro.apache.org/docs/1.8.1/spec.html#schema_record

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器