sql – Hive – 重命名具有相同名称的字段作为数据类型

我有一个像这样的Hive表:

CREATE TABLE mytest (name int, timestamp bigint, donation int);

我正在使用Hive 0.12.请注意字段“timestamp”.顺便提一下,Hive 0.12引入了一种名为timestamp的新数据类型.假设我想将此字段重命名为time_stamp

我试过这些:

> ALTER TABLE mytest CHANGE timestamp time_stamp BIGINT;
> ALTER TABLE mytest CHANGE COLUMN timestamp time_stamp BIGINT;
> ALTER TABLE mytest CHANGE [timestamp] time_stamp BIGINT;
> ALTER TABLE mytest CHANGE`timestamp`time_stamp BIGINT;

但是,所有这些都给我以下错误:

FAILED: ParseException line 1:38 mismatched input 'CHANGE' expecting KW_EXCHANGE near 'mytest' in alter exchange partition

我确定这是因为我的字段名称与数据类型名称相同.如何更改mytest的架构而无需执行以下操作?

CREATE mytest_cpy AS SELECT mytest.name, mytest.timestamp AS time_stamp, 
mytest.donation FROM mytest; 

DROP TABLE mytest; 

ALTER TABLE mytest_cpy RENAME TO mytest;

谢谢!任何/所有帮助表示赞赏!

最佳答案 对任何包含奇怪符号或与数据类型相同的不常列名称使用反引号.这适用于Hive 0.14:

ALTER TABLE mytest CHANGE COLUMN `timestamp` time_stamp BIGINT;
点赞