alter hive multiple column

2019-05-28 07:14发布

How do we alter the datatype of multiple columns in Hive ?

CREATE TABLE test_change (a int, b int, c int);

ALTER TABLE test_change CHANGE a a string b b doube c c decimal(11,2);

1条回答
仙女界的扛把子
2楼-- · 2019-05-28 07:28

As far as I know, you can't. In the Hive documentation you can find the following:

ALTER TABLE table_name [PARTITION partition_spec] CHANGE [COLUMN] col_old_name col_new_name column_type [COMMENT col_comment] [FIRST|AFTER column_name] [CASCADE|RESTRICT];

This command will allow users to change a column's name, data type, comment, or position, or an arbitrary combination of them. The PARTITION clause is available in Hive 0.14.0 and later; see Upgrading Pre-Hive 0.13.0 Decimal Columns for usage. A patch for Hive 0.13 is also available (see HIVE-7971).

The documentation is speaking about "a column". The alternative would be to write multiple queries, one for each datatype you have to change.

Reference: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL

查看更多
登录 后发表回答