我正在使用Avro(使用python库)序列化某些数据,并且很难确定如何使“默认”值起作用。
我有这个模式:
{
"type": "record","fields":[
{"name": "amount","type": "long"},{"name": "currency","type": "string","default": "EUR"}
],"name": "Monetary",}
据我所知,我可以传递金额而不输入货币,货币字段将采用“ EUR”值。但是,如果在编写时未传递“ currency”字段,则会收到错误avro.io.AvroTypeException: The datum { ... } is not an example of the schema xxx
...
如果我将货币字段的类型替换为联合["string","null"]
,则数据将被序列化,但货币为null。
因此似乎根本没有考虑“默认”值。
我想念什么?默认值是否适用于基本类型?
预先感谢