【问题标题】:Avro schema record field name start from numberAvro 模式记录字段名称从数字开始
【发布时间】:2018-01-18 16:32:53
【问题描述】:

Avro 文档说:

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

  • 从 [A-Za-z_] 开始
  • 随后仅包含 [A-Za-z0-9_]

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

【问题讨论】:

    标签: avro avro-tools


    【解决方案1】:

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

    {
        "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”等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多