Avro模式故障 [英] Avro Schema failure
问题描述
我有以下对象:
[
{"ProductId":10,"ProductName":"some name"}
]
Bu有时候我只有 null
.我试图为此提出一个模式.但这似乎不起作用:(.
Bu sometimes I have just null
. I am trying to come up with a schema for this. But it doesn't seem to work :(.
我尝试了以下两种方法:
I tried the following two:
{
"name": "ProductsOrNull",
"type": ["null", {
"type": "array",
"name": "Products",
"items": {
"type":"record",
"name": "Product",
"fields": [{
"name":"ProductId",
"type":"long"
}, {
"name":"ProductName",
"type":"string"
}
]
}
}],
"default": null
}
但是在运行" java -jar avro-tools-"时,它在线程"main" org.apache.avro.SchemaParseException中出现
. Exception失败:无类型:< ...>
1.8.2.jar fromjson --schema文件prod.avsc prod.json>lol.avro
But it fails with Exception in thread "main" org.apache.avro.SchemaParseException: No type: <...>
when running java -jar avro-tools-1.8.2.jar fromjson --schema-file prod.avsc prod.json > lol.avro
.
我也尝试了同样的错误:
I also trie this with the same error:
{
"type": ["null", "array"],
"name": "Products",
"items": {
"type":"record",
"name": "Product",
"namespace": "{{ dataModelSchema }}",
"fields": [{
"name":"ProductId",
"type":"long"
}, {
"name":"ProductName",
"type":"string"
}
]
}
}
我真的不明白问题出在哪里,两者之间有什么区别.
I don't really understand where the problem is and what is the difference between the two.
推荐答案
基于您的模式,您的json对象应类似于
Base on your schemas, your json object should look like
{
"ProductsOrNull" :
[
{"ProductId":10,"ProductName":"some name"}
]
}
无法使用没有字段名称的数组定义和avro模式.
There is no way to define and avro schema with an array without a field name.
这篇关于Avro模式故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!