你能在Avro JSON架构文件中添加评论吗?

jfr*_*z42 8 json avro

我正在编写我的第一个Avro架构,它使用JSON作为架构语言.我知道你不能把评论放到普通的JSON中,但我想知道Avro工具是否允许评论.例如,在解析JSON之前,它可能会剥离它们(就像预处理器一样).

编辑:我正在使用C++ Avro工具链

Joh*_*ugh 10

是的,但它是有限的.在模式中,Avro数据类型"record","enum"和"fixed"允许包含任意文档字符串的"doc"字段.例如:

{"type": "record", "name": "test.Weather",
 "doc": "A weather reading.",
 "fields": [
     {"name": "station", "type": "string", "order": "ignore"},
     {"name": "time", "type": "long"},
     {"name": "temp", "type": "int"}
 ]
}
Run Code Online (Sandbox Code Playgroud)

来自https://github.com/apache/avro/blob/33d495840c896b693b7f37b5ec786ac1acacd3b4/share/test/schemas/weather.avsc#L2


Gae*_* E. 7

是的,您可以在Avro JSON模式中使用C注释:/* something */ or // something
Avro工具在解析期间忽略这些表达式.
编辑:它只适用于Java API.


Ras*_*åth 5

根据当前 ( 1.9.2) Avro 规范,允许添加未定义的额外属性作为元数据:

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"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)