Avro - 为每个字段添加 doc/description

Avro - Add doc/description for each field

我们正在使用 avro 进行模式定义。是否可以为 avro.xml 中的每个字段添加字段描述?我同意我们可以在记录级别添加 'doc'。我们想在字段级别添加描述。

您也可以在字段级别添加 doc

val str =
  """
    |{
    |  "type": "record",
    |  "name": "TestRecord",
    |  "namespace": "org.apache.avro.test",
    |  "doc": "test schema",
    |  "fields": [
    |    {
    |      "name": "name",
    |      "type": {
    |        "type": "string"
    |      },
    |      "doc": "this is name"
    |    },
    |    {
    |      "name": "age",
    |      "type": {
    |        "type": "long"
    |      },
    |      "doc": "this is age"
    |    }
    |  ]
    |}
    |""".stripMargin
val schema = new Schema.Parser().parse(str)

println(schema.getDoc)
schema.getFields.forEach(field => println(field.doc()))

输出:

test schema
this is name
this is age