gpt4 book ai didi

json - Avro模式格式异常- "record"不是定义的名称

转载 作者:行者123 更新时间:2023-12-04 11:34:24 25 4
gpt4 key购买 nike

我正在尝试使用此Avro Shcema

{
"namespace": "nothing",
"name": "myAvroSchema",
"type": "record",
"fields": [
{
"name": "checkInCustomerReference",
"type": "string"
},
{
"name": "customerContacts",
"type": "record",
"fields": [
{
"name": "customerEmail",
"type": "array",
"items": {
"type": "record",
"name": "customerEmail_element",
"fields": [
{
"name": "emailAddress",
"type": "string"
},
{
"name": "typeOfEmail",
"type": "string"
}
]
}
},
{
"name": "customerPhone",
"type": "array",
"items": {
"type": "record",
"name": "customerPhone_element",
"fields": [
{
"name": "fullContactNumber",
"type": "string"
},
{
"name": "ISDCode",
"type": "string"
}
]
}
},
{
"name": "DonotAskIndicator",
"type": "record",
"fields": [
{
"name": "donotAskDetails",
"type": "string"
}
]
}
]
},
{
"name": "somethingElseToCheck",
"type": "string"
}
]
}

要使用avro工具生成和avro文件,请执行以下操作:
avro-tools fromjson --schema-file myAvroSchema.avsc myJson.json > myAvroData.avro

但是我收到以下错误消息:

Exception in thread "main" org.apache.avro.SchemaParseException: "record" is not a defined name. The type of the "customerContacts" field must be a defined name or a {"type": ...} expression.



谁能告诉我为什么记录未标识为已定义名称?

最佳答案

The type of the "customerContacts" field must be a defined name or a {"type": ...} expression



看起来好像您没有正确定义嵌套记录。我重现了您的架构,并给出了一个尝试:
{  
"type":"record",
"name":"myAvroSchema",
"namespace":"nothing",
"fields":[
{
"name":"checkInCustomerReference",
"type":"string"
},
{
"name":"customerContacts",
"type":{
"type":"record",
"name":"customerContacts",
"namespace":"nothing",
"fields":[
{
"name":"customerEmail",
"type":{
"type":"array",
"items":{
"type":"record",
"name":"customerEmail",
"namespace":"nothing",
"fields":[
{
"name":"emailAddress",
"type":"string"
},
{
"name":"typeOfEmail",
"type":"string"
}
]
}
}
},
{
"name":"customerPhone",
"type":{
"type":"array",
"items":{
"type":"record",
"name":"customerPhone",
"namespace":"nothing",
"fields":[
{
"name":"fullContactNumber",
"type":"string"
},
{
"name":"ISDCode",
"type":"string"
}
]
}
}
},
{
"name":"DonotAskIndicator",
"type":{
"type":"record",
"name":"donotAskIndicator",
"namespace":"nothing",
"fields":[
{
"name":"donotAskDetails",
"type":"string"
}
]
}
}
]
}
},
{
"name":"somethingElseToCheck",
"type":"string"
}
]
}

关于json - Avro模式格式异常- "record"不是定义的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43513140/

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