Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Add comments to columns in an impala table

Solved Go to solution
Highlighted

Add comments to columns in an impala table

Explorer

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

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Add comments to columns in an impala table

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') |
+---------------------------------------------------------------------------------------------------------------------+
7 REPLIES 7

Re: Add comments to columns in an impala table

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

Re: Add comments to columns in an impala table

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') |
+---------------------------------------------------------------------------------------------------------------------+

Re: Add comments to columns in an impala table

New Contributor

Hi, here is a question.

How do I alter and remove a table comment?

THANKS.

Re: Add comments to columns in an impala table

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

Re: Add comments to columns in an impala table

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.

Re: Add comments to columns in an impala table

Cloudera Employee

Re: Add comments to columns in an impala table

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
Don't have an account?
Coming from Hortonworks? Activate your account here