gpt4 book ai didi

Avro-Tools JSON 到 Avro 架构失败 : org. apache.avro.SchemaParseException:未定义名称:

转载 作者:行者123 更新时间:2023-12-04 01:34:07 26 4
gpt4 key购买 nike

我正在尝试使用 avro-tools-1.7.4.jar create schema 命令创建两个 Avro 模式。

我有两个 JSON 模式,如下所示:

{
"name": "TestAvro",
"type": "record",
"namespace": "com.avro.test",
"fields": [
{"name": "first", "type": "string"},
{"name": "last", "type": "string"},
{"name": "amount", "type": "double"}
]
}


{
"name": "TestArrayAvro",
"type": "record",
"namespace": "com.avro.test",
"fields": [
{"name": "date", "type": "string"},
{"name": "records", "type":
{"type":"array","items":"com.avro.test.TestAvro"}}
]
}

当我在这两个文件上运行 create schema 时,第一个工作正常并生成 java.lang.第二个每次都失败。当我尝试使用第一个 Schema 作为类型时,它不喜欢数组项。这是我得到的错误:
Exception in thread "main" org.apache.avro.SchemaParseException: Undefined name: "com.test.avro.TestAvro"
at org.apache.avro.Schema.parse(Schema.java:1052)

这两个文件位于同一路径目录中。

最佳答案

使用以下 avsc 文件:

[{
"name": "TestAvro",
"type": "record",
"namespace": "com.avro.test",
"fields": [
{
"name": "first",
"type": "string"
},
{
"name": "last",
"type": "string"
},
{
"name": "amount",
"type": "double"
}
]
},
{
"name": "TestArrayAvro",
"type": "record",
"namespace": "com.avro.test",
"fields": [
{
"name": "date",
"type": "string"
},
{
"name": "records",
"type": {
"type": "array",
"items": "com.avro.test.TestAvro"
}
}
]
}]

关于Avro-Tools JSON 到 Avro 架构失败 : org. apache.avro.SchemaParseException:未定义名称:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22443051/

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