1

We are using avro for our schema definition. Is it possible to add field description for each of the fields in avro. I agree that we can add 'doc' at record level. we wanted to add description at a field level.

SunilS
  • 2,030
  • 5
  • 34
  • 62

1 Answers1

3

You can add doc at field level too.

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()))

output:

test schema
this is name
this is age
moon
  • 1,702
  • 3
  • 19
  • 35