gpt4 book ai didi

json - 无法在 Golang 中解析 A​​VRO 模式

转载 作者:IT王子 更新时间:2023-10-29 02:19:44 25 4
gpt4 key购买 nike

我在解析我的 AVRO json 架构时遇到问题。我尝试使用此库中的 avro.ParseSchema 函数:https://github.com/go-avro/avro .但是,我收到以下错误消息:

Unknown type name: array

很长一段时间以来,我一直在努力解决这个问题,但我似乎无法解决问题。我实现了以下结构:

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"}
}
]
}
}

]
}`)

如有任何帮助,我们将不胜感激。

最佳答案

在记录字段中,你不能说 "type": "array";您需要使“类型”成为有效的 avro 模式,而不是有效的 avro 类型。

尝试以下操作:

{
"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"
}
}
}
]
}
}
}
]
}

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

关于json - 无法在 Golang 中解析 A​​VRO 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54694403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com