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 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch