【问题标题】:Avro - Add doc/description for each fieldAvro - 为每个字段添加文档/描述
【发布时间】:2020-05-20 11:46:47
【问题描述】:

我们使用 avro 进行架构定义。是否可以为 avro 中的每个字段添加字段描述。我同意我们可以在记录级别添加“文档”。我们想在字段级别添加描述。

【问题讨论】:

    标签: avro spark-avro avsc


    【解决方案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
    

    【讨论】:

    • avdl 的任何文档样本?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    相关资源
    最近更新 更多