Avro - 为每个字段添加docdescription。

问题描述 投票:0回答:1

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

avro spark-avro avsc
1个回答
1
投票

你可以添加 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
© www.soinside.com 2019 - 2024. All rights reserved.