Avro - 为每个字段添加文档/描述



我们使用avro作为我们的模式定义。是否可以为 avro 中的每个字段添加字段描述。我同意我们可以在记录级别添加"文档"。我们希望在字段级别添加描述。

您也可以在字段级别添加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

最新更新