hadoop - 不能在 Hive 表列名中使用 "."

标签 hadoop hive hiveql emr

我正在使用 Hive 2.1.1 并尝试在列名称中使用 . 创建一个表:

CREATE TABLE `test_table`(
  `field.with.dots` string
);

当我这样做时,我得到:

FAILED: ParseException line 4:0 Failed to recognize predicate ')'. Failed rule: '[., :] can not be used in column name in create table statement.' in column specification

我一定是做错了什么,因为 hive documentation说:

In Hive release 0.13.0 and later, by default column names can be specified within backticks (`) and contain any Unicode character (HIVE-6013)

. 是一个 unicode 字符。知道我可能在做什么吗?

为了向您提供更多上下文,这是在 Amazon EMR 5.5.0 集群上进行的。谢谢!

最佳答案

源代码:HiveParser

...
private char [] excludedCharForColumnName = {'.', ':'};
...

  private CommonTree throwColumnNameException() throws RecognitionException {
    throw new FailedPredicateException(input, Arrays.toString(excludedCharForColumnName) + " can not be used in column name in create table statement.", "");
  }

Jira 票证:Disallow create table with dot/colon in column name

请注意动机:

Since we don't allow users to query column names with dot in the middle such as emp.no, don't allow users to create tables with such columns that cannot be queried

似乎 create table 被处理了,但不是 CTAS 也不是 ALTER TABLE...

hive> create table t as select 1 as `a.b.c`;
OK
hive> desc t;
OK
col_name    data_type   comment
a.b.c                   int                                         
Time taken: 0.441 seconds, Fetched: 1 row(s)
hive> select * from t;
FAILED: RuntimeException java.lang.RuntimeException: cannot find field a from [0:a.b.c]

hive> create table t (i int);
OK
hive> alter table t change column i `a.b.c` int
hive> select * from t;
Error while compiling statement: FAILED: RuntimeException java.lang.RuntimeException: cannot find field a from [0:a.b.c]

附言

我已经更新了文档(查找冒号) https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL

关于hadoop - 不能在 Hive 表列名中使用 ".",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43808435/

相关文章:

time - hive 将 PHT 时间转换为 UTC

hadoop - 针对低资源调优 Hadoop

java - Hive UDF Run:在Hive中创建临时函数时出错

hadoop - 更改配置单元中的列类型

arrays - 配置单元 : casting array<string> to array<int> in query

sql - Hive 查询中的语法错误

Hadoop - 在查询中声明变量时出现错误消息

java - 在 hive-site.xml 中查找 _HOST 的值

hadoop - 我可以在电子商务(Magento)中使用大数据吗?

hadoop - HiveContext 不适用于 Oozie