Support Questions

Find answers, ask questions, and share your expertise

Add comments to columns in an impala table

avatar
Contributor

How do I add comments to a column in an impala table for specific columns after creating it.

 

Thanks

1 ACCEPTED SOLUTION

avatar
Super Guru
ALTER TABLE test CHANGE {columname} {columnname} {datatype} comment 'test comment';


See below test case:

 

[impala-host:21000] > show create table test;
Query: show create table test
+---------------------------------------------------------------------------------------------------------------------+
| result                                                                                                              |
+---------------------------------------------------------------------------------------------------------------------+
| CREATE TABLE default.test (                                                                                         |
|   a INT,                                                                                                            |
|   b INT                                                                                                             |
| )                                                                                                                   |
| WITH SERDEPROPERTIES ('serialization.format'='1')                                                                   |
| STORED AS TEXTFILE                                                                                                  |
| LOCATION 'hdfs://namenode-host:8020/user/hive/warehouse/test'                                 |
| TBLPROPERTIES ('numFiles'='3', 'COLUMN_STATS_ACCURATE'='true', 'numRows'='9', 'totalSize'='40', 'rawDataSize'='31') |
+---------------------------------------------------------------------------------------------------------------------+
Fetched 1 row(s) in 7.42s
[impala-host:21000] > alter table test change a a int comment 'test comment';
Query: alter table test change a a int comment 'test comment'

Fetched 0 row(s) in 0.66s
[impala-host:21000] > show create table test;
Query: show create table test
+---------------------------------------------------------------------------------------------------------------------+
| result                                                                                                              |
+---------------------------------------------------------------------------------------------------------------------+
| CREATE TABLE default.test (                                                                                         |
|   a INT COMMENT 'test comment',                                                                                     |
|   b INT                                                                                                             |
| )                                                                                                                   |
| WITH SERDEPROPERTIES ('serialization.format'='1')                                                                   |
| STORED AS TEXTFILE                                                                                                  |
| LOCATION 'hdfs://namenode-host:8020/user/hive/warehouse/test'                                 |
| TBLPROPERTIES ('numFiles'='3', 'COLUMN_STATS_ACCURATE'='true', 'numRows'='9', 'totalSize'='40', 'rawDataSize'='31') |
+---------------------------------------------------------------------------------------------------------------------+

View solution in original post

7 REPLIES 7

avatar
Champion

@gimp077

 

I didn't get a chance to test it, but just try this, it may help

 

Go to Hue -> Metastore manager -> db.table -> property -> update comment

avatar
Super Guru
ALTER TABLE test CHANGE {columname} {columnname} {datatype} comment 'test comment';


See below test case:

 

[impala-host:21000] > show create table test;
Query: show create table test
+---------------------------------------------------------------------------------------------------------------------+
| result                                                                                                              |
+---------------------------------------------------------------------------------------------------------------------+
| CREATE TABLE default.test (                                                                                         |
|   a INT,                                                                                                            |
|   b INT                                                                                                             |
| )                                                                                                                   |
| WITH SERDEPROPERTIES ('serialization.format'='1')                                                                   |
| STORED AS TEXTFILE                                                                                                  |
| LOCATION 'hdfs://namenode-host:8020/user/hive/warehouse/test'                                 |
| TBLPROPERTIES ('numFiles'='3', 'COLUMN_STATS_ACCURATE'='true', 'numRows'='9', 'totalSize'='40', 'rawDataSize'='31') |
+---------------------------------------------------------------------------------------------------------------------+
Fetched 1 row(s) in 7.42s
[impala-host:21000] > alter table test change a a int comment 'test comment';
Query: alter table test change a a int comment 'test comment'

Fetched 0 row(s) in 0.66s
[impala-host:21000] > show create table test;
Query: show create table test
+---------------------------------------------------------------------------------------------------------------------+
| result                                                                                                              |
+---------------------------------------------------------------------------------------------------------------------+
| CREATE TABLE default.test (                                                                                         |
|   a INT COMMENT 'test comment',                                                                                     |
|   b INT                                                                                                             |
| )                                                                                                                   |
| WITH SERDEPROPERTIES ('serialization.format'='1')                                                                   |
| STORED AS TEXTFILE                                                                                                  |
| LOCATION 'hdfs://namenode-host:8020/user/hive/warehouse/test'                                 |
| TBLPROPERTIES ('numFiles'='3', 'COLUMN_STATS_ACCURATE'='true', 'numRows'='9', 'totalSize'='40', 'rawDataSize'='31') |
+---------------------------------------------------------------------------------------------------------------------+

avatar
New Contributor

Hi, here is a question.

How do I alter and remove a table comment?

THANKS.

avatar
Super Guru
Hi,

You could just set the comment as empty string like "", I am not sure if you can remove the field completely.

Cheers
Eric

avatar
New Contributor

Thanks for your quick reply.

What I wanna know is how do I alter and remove a "table level" comment.

I cannot find an example or document on the Internet.

avatar
Contributor

avatar
Super Guru
You can do alter like I mentioned before:

ALTER TABLE test CHANGE col1 col1 int COMMENT 'test comment';

But I do not think you can remove it, but rather to just empty it.

Cheers
Eric