创建表名中包含连字符(-)的 Hive 表

Ale*_*lás 3 sql hadoop hive

我需要在 Hive (v-1.2.2) 中创建一个表,表名中包含连字符 (-)。

阅读 Hive文档,我尝试使用反引号 (`) 对表名称进行圆整,但失败了。

查询已执行

CREATE EXTERNAL TABLE `kpisample_MarkContent_db786910-bd59-11e7-8329-9f28c9dd3095` STORED AS AVRO LOCATION '/prod/kpisample/dataset=0c253b00-2f04-11e6-ae13-d90f2a2beea0/KPI_id=MarkContent/year=2019/month=11/day=18/hour=4/' TBLPROPERTIES ('avro.schema.url'='/prod/schemas/kpisample/dataset=0c253b00-2f04-11e6-ae13-d90f2a2beea0/KPI_id=MarkContent/kpisetting_MarkContent.avsc');

失败信息

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org.apache.hadoop.hive.ql.metadata.HiveException: [kpisample_MarkContent_db786910-bd59-11e7-8329-9f28c9dd3095]: is not a valid table name

有什么办法可以做到吗?

感谢你的帮助。

dam*_*eng 5

实际上,包含的表名-是不合法的。
源代码显示表名中 org.apache.hadoop.hive.metastore.MetaStoreUtils只允许使用字符数字下划线:

/**
   * validateName
   *
   * Checks the name conforms to our standars which are: "[a-zA-z_0-9]+". checks
   * this is just characters and numbers and _
   * ...
   */
  static public boolean validateName(String name) {
    Pattern tpat = Pattern.compile("[\\w_]+");
    Matcher m = tpat.matcher(name);
    if (m.matches()) {
      return true;
    }
    return false;
  }
Run Code Online (Sandbox Code Playgroud)