我正在尝试重命名Hive中的columnName。有没有办法在Hive中重命名列名。
tableA(column1,_c1,_c2) 至 表A(列1,列2,栏3) ??
答案 0 :(得分:63)
Change Column Name/Type/Position/Comment:
ALTER TABLE table_name CHANGE [COLUMN] col_old_name col_new_name column_type [COMMENT col_comment] [FIRST|AFTER column_name]
示例:
CREATE TABLE test_change (a int, b int, c int);
// will change column a's name to a1
ALTER TABLE test_change CHANGE a a1 INT;
答案 1 :(得分:6)
命令仅在首次使用“use”命令定义工作的数据库时才有效。使用DATABASE.TABLE重命名表列会引发错误并且不起作用。版本:HIVE 0.12。
实施例
hive> ALTER TABLE databasename.tablename CHANGE old_column_name new_column_name;
MismatchedTokenException(49!=90)
at org.antlr.runtime.BaseRecognizer.recoverFromMismatchedToken(BaseRecognizer.java:617)
at org.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:115)
at org.apache.hadoop.hive.ql.parse.HiveParser.alterStatementSuffixExchangePartition(HiveParser.java:11492)
...
hive> use databasename;
hive> ALTER TABLE tablename CHANGE old_column_name new_column_name;
OK
答案 2 :(得分:1)
alter table table_name change old_col_name new_col_name new_col_type;
以下是示例
hive> alter table test change userVisit userVisit2 STRING;
OK
Time taken: 0.26 seconds
hive> describe test;
OK
uservisit2 string
category string
uuid string
Time taken: 0.213 seconds, Fetched: 3 row(s)
答案 3 :(得分:1)