我正在编写我的第一个 Avro 模式,它使用 JSON 作为模式语言。我知道您不能将评论放入纯 JSON,但我想知道 Avro 工具是否允许评论。例如,也许它会在解析 JSON 之前剥离它们(如预处理器)。
编辑:我正在使用 C++ Avro 工具链
是的,但它是有限的。在架构中,Avro 数据类型“记录”、“枚举”和“固定”允许包含任意文档字符串的“文档”字段。例如:
{"type": "record", "name": "test.Weather",
"doc": "A weather reading.",
"fields": [
{"name": "station", "type": "string", "order": "ignore"},
{"name": "time", "type": "long"},
{"name": "temp", "type": "int"}
]
}
来自官方 Avro 规范:
doc:一个 JSON 字符串,为该模式的用户提供文档(可选)。
https://avro.apache.org/docs/current/spec.html#schema_record
是的,您可以在 Avro JSON 模式中使用 C 注释:/* something */ or // something
Avro 工具在解析期间会忽略这些表达式。
编辑:它只适用于 Java API。
根据当前 ( 1.9.2
) Avro 规范,允许将未定义的额外属性作为元数据放入:
这允许您添加如下评论:
{
"type": "record",
"name": "test",
"comment": "This is a comment",
"//": "This is also a comment",
"TODO": "As per this comment we should remember to fix this schema" ,
"fields" : [
{
"name": "a", "type": "long"
},
{
"name": "b", "type": "string"
}
]
}
不,它不能在 C++ 和 C# 版本中(从 1.7.5 开始)。如果您查看代码,他们只是将 JSON 推入 JSON 解析器,没有任何注释预处理 - 奇怪的编程风格。文档和语言支持似乎很草率......