【发布时间】:2017-12-15 12:01:38
【问题描述】:
我有以下对象:
[
{"ProductId":10,"ProductName":"some name"}
]
但有时我只有null。我正在尝试为此提出一个架构。但这似乎不起作用:(。
我尝试了以下两种:
{
"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-1.8.2.jar fromjson --schema-file prod.avsc prod.json > lol.avro 时它会以Exception in thread "main" org.apache.avro.SchemaParseException: No type: <...> 失败。
我也尝试过同样的错误:
{
"type": ["null", "array"],
"name": "Products",
"items": {
"type":"record",
"name": "Product",
"namespace": "{{ dataModelSchema }}",
"fields": [{
"name":"ProductId",
"type":"long"
}, {
"name":"ProductName",
"type":"string"
}
]
}
}
我不太明白问题出在哪里,两者有什么区别。
【问题讨论】:
标签: avro