Column Comments in Apache Hive

There will be certain database objects introduced during deployments and hotfixes. Comments are frequently used to indicate which item is introduced in which deployment. However, this is true for OLTP.

Comments are also necessary to understand why the object was formed and what information it would store. This is applicable to both OLTP and OLAP.

While creating the database, table, and table columns, Apache Hive allows you to add comments. These comments can be left blank if you don’t want to. In this post, we’ll look at how to add column comments.

Here is the syntax to add comments while creating the table.

CREATE [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.]table_name
(col_name data_type [COMMENT ‘col_comment’],, …)
[COMMENT ‘table_comment’]
[ROW FORMAT row_format]
[FIELDS TERMINATED BY char]
[STORED AS file_format];

Example:
CREATE TABLE tbEmp
    ( EmpID STRING COMMENT ‘Employee Identity Number’,
      EName STRING COMMENT ‘This column holds the names of the employees’,
      DName STRING COMMENT ‘This column holds names of the employee’s departments’,)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ‘ ‘
STORED AS TEXTFILE;

In order to view the comments of the table, use DESC FORMATTED <tableName> command.

Hope you find this article helpful.

Please subscribe for more interesting updates.

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s