|
|
How to alter table in HCatalog?
Here, this chapter describes about how to alter the different attributes of a table such as changing its table name, changing column names, adding columns, and deleting or replacing columns.
You can use the ALTER TABLE statement to alter a table in Hive.
The statement takes any of the following syntaxes based on what attributes we wish to modify in a table.
Few scenarios are explained below.
The following query renames a table from employee to emp.
Below mentioned table contains the fields of employee table and it shows the fields to be changed (in bold).
Field Name |
Convert from Data Type |
Change Field Name |
Convert to Data Type |
eid |
int |
eid |
int |
name |
String |
ename |
String |
salary |
Float |
salary |
Double |
designation |
String |
designation |
String |
The following queries rename the column name and column data type using the above data –
The following query adds a column named dept to the employee table.
Below query deletes all the columns from the employee table and replaces it with emp and name columns –
When you drop a table from the metastore, it removes the table/column data and their metadata. It can be a normal table (stored in metastore) or an external table (stored in local file system); HCatalog treats both in the same manner, irrespective of their types.
The syntax is as follows –
The following query drops a table named employee –
On successful execution of the query, you get to see the following response
|
|
HCatalog Related Practice Tests |
|
---|---|
RDBMS Practice Tests | Core Java Practice Tests |
MySQL Practice Tests | Hadoop Practice Tests |
Apache HBase Practice Tests |
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.