Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change column comments in existing Hive table without including new column name and type?

Tags:

hive

I want to change the column comments on an existing hive table using hive 0.13. This works:

create table test (mycolumn int); alter table test change mycolumn mycolumn int comment 'hello';

But I can't find a way to do this without repeating the name of the column and the type, both of which are irrelevant to the change. For example:

alter table test change mycolumn comment 'hello'; leads to an error.

If this was for one column it would not be a big deal but I want to do this for large numbers of columns in tables that were not commented. I know this could be done with a script that simply copies the column name and its type but would be nice to know if there were something simpler. Thanks

like image 608
user2793761 Avatar asked Mar 23 '15 16:03

user2793761


2 Answers

You can do this using ALTER command.

CREATE TABLE my_table
(id INT COMMENT 'id comment',
name STRING comment 'name comment');

-- change column comment as below.
ALTER TABLE my_table CHANGE id id INT COMMENT 'another comment';
-- see changed column
DESC EXTENDED my_table;
like image 86
Piyush Patel Avatar answered Nov 15 '22 09:11

Piyush Patel


ALTER TABLE test_change CHANGE a1 a1 INT COMMENT 'this is column a1';
like image 31
simon Avatar answered Nov 15 '22 08:11

simon