我有一个这样的 Hive 表:
CREATE TABLE mytest (name int, timestamp bigint, donation int);
我正在使用 Hive 0.12。注意字段“时间戳”。顺便说一句,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;
关于sql - Hive - 重命名与数据类型同名的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23416733/