HCatalog Alter Table


HCatalog Alter Table

This post descibes, how to alter the attributes of a table such as changing its table name, changing column names, adding columns, and deleting or replacing columns.

Step 1 - Open a new terminal (CTRL + ALT + T) and Change the directory to /usr/local/hive/hcatalog/bin




$ cd $HCAT_HOME/bin

Step 2 - Creating a new employee table




$ ./hcat -e "CREATE TABLE IF NOT EXISTS employee( eid int, name String, salary String, destination String) \
COMMENT 'Employee details' \
ROW FORMAT DEIMITED \
FIELDS TERMINATED BY ' ' \
LINES TERMINATED BY '\n' \
STORED AS TEXTFILE;"


Step 3 - Check whether it is created or not. It shows all the tables that are present.




$ ./hcat -e "show tables;"

Step 4 - Altering Table

Alter table name




$ ./hcat -e "ALTER TABLE employee RENAME TO emp;"
$ ./hcat -e "ALTER TABLE emp RENAME TO employee;"


Change column name and type




$ ./hcat -e "ALTER TABLE employee CHANGE name ename String;"
$ ./hcat -e "ALTER TABLE employee CHANGE salary salary Double;"


Add column




$ ./hcat -e "ALTER TABLE employee ADD COLUMNS (dept STRING COMMENT 'Department name');"

Replace column name




$ ./hcat -e "ALTER TABLE employee REPLACE COLUMNS (eid int,empid int);"

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *