【发布时间】:2020-05-20 11:46:47
【问题描述】:
我们使用 avro 进行架构定义。是否可以为 avro 中的每个字段添加字段描述。我同意我们可以在记录级别添加“文档”。我们想在字段级别添加描述。
【问题讨论】:
标签: avro spark-avro avsc
我们使用 avro 进行架构定义。是否可以为 avro 中的每个字段添加字段描述。我同意我们可以在记录级别添加“文档”。我们想在字段级别添加描述。
【问题讨论】:
标签: avro spark-avro avsc
您也可以在字段级别添加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
【讨论】: