Avro架构记录字段名称从数字开始

时间:2018-01-18 16:32:54

标签: avro avro-tools

Avro文档说:

  

全名,记录字段名称和枚举符号的名称部分必须:

     
      
  • 以[A-Za-z _]
  • 开头   
  • 随后仅包含[A-Za-z0-9 _]
  •   

是否有可能以某种方式逃避第一条规则,并且记录字段名称以数字开头,即123ColumnName?也许通过“逃避”或特殊的“符号”?

1 个答案:

答案 0 :(得分:0)

通过用下划线(_)“转义”,您可能具有以数字开头的字段名称。

{
    "namespace" : "com.test",
    "type" : "record",
    "name" : "digit",
    "fields": [ 
        { "name" : "_1ColumnName", "type" : ["null", "string"], "default" : null },
        { "name" : "_2ColumnName", "type" : ["null", "string"], "default" : null },
        { "name" : "_2ColumnName", "type" : ["null", "string"], "default" : null }
    ]
}

尽管我不建议这样做,因为稍后访问这些字段会有些棘手。例如,您可能考虑将字段命名为“ f1ColumnName”,“ f2ColumnName”等等。

相关问题