【发布时间】:2013-05-23 01:39:04
【问题描述】:
我正在编写我的第一个 Avro 架构,它使用 JSON 作为架构语言。我知道您不能将 cmets 放入纯 JSON,但我想知道 Avro 工具是否允许 cmets。例如。也许它会在解析 JSON 之前剥离它们(如预处理器)。
编辑:我正在使用 C++ Avro 工具链
【问题讨论】:
我正在编写我的第一个 Avro 架构,它使用 JSON 作为架构语言。我知道您不能将 cmets 放入纯 JSON,但我想知道 Avro 工具是否允许 cmets。例如。也许它会在解析 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 cmets:/* something */ or // something
Avro 工具在解析期间会忽略这些表达式。
编辑:它只适用于 Java API。
【讨论】:
根据the current (1.9.2) Avro specification,允许将未定义的额外属性作为元数据放入:
这允许您像这样添加 cmets:
{
"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 解析器而没有任何注释预处理 - 奇怪的编程风格。文档和语言支持似乎很草率...
【讨论】: