简体   繁体   English

有没有办法改变hive表中的列类型?

[英]Is there a way to alter column type in hive table?

The current schema is: 目前的架构是:

hive> describe tableA;
OK
id      int
ts      timestamp

I want to change ts column to be BIGINT without dropping table and recreate again. 我想在不丢弃表的情况下将ts列更改为BIGINT并再次重新创建。 Is it possible? 可能吗?

Found the solution: 找到解决方案:

ALTER TABLE tableA CHANGE ts ts BIGINT AFTER id;

See this for complete details: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AlterColumn 有关完整的详细信息,请参阅此处: https//cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AlterColumn

ALTER TABLE table_name CHANGE col_name col_name newType

It's simple usually to change/modify the exesting table use this syntax in Hive. 通常更改/修改exesting表在Hive中使用此语法很简单。

ALTER TABLE table_name CHANGE old_col_name new_col_name new_data_type

Here you can change your column name and data type at a time. 您可以在此处一次更改列名和数据类型。 If you don't want to change col_name simply makes old_col_name and new_col_name are same. 如果您不想更改col_name,只需使old_col_name和new_col_name相同即可。 Ok. 好。

Come to your problem. 来你的问题。 If you want to change ts column to be BIGINT.It means column-type you are changing. 如果要将ts列更改为BIGINT。这意味着您要更改的列类型。 so simply run this query. 所以只需运行此查询。

ALTER TABLE tableA CHANGE ts ts BIGINT;

Here ts and ts are same, means you are not changing column name, but changing column-type; 这里ts和ts相同,意味着你不是要改变列名,而是改变列类型; if you wish to change column name also simply run it. 如果您想更改列名,也只需运行它。

ALTER TABLE tableA CHANGE ts new_col BIGINT;

Now run 现在跑

hive> describe tableA;
OK
id      int
new_col      bigint

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM