我正在使用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说:
在Hive版本0.13.0及更高版本中,默认情况下可以在反引号(`)中指定列名并包含任何Unicode字符(HIVE-6013)
.
是一个unicode角色。并了解我可能在做什么?
为了向您提供更多上下文,这是在Amazon EMR 5.5.0群集上。谢谢!
答案 0 :(得分:5)
源代码: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 ticket:Disallow create table with dot/colon in column name
请注意动机:
因为我们不允许用户查询带有点的列名 中间如emp.no,不允许用户使用这样的表创建表 无法查询的列
似乎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]
<强> P.S。强>
我更新了文档(查找colon
)
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL