HCatalog Alter Table - HCatalog

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.

Alter Table Statement

You can use the ALTER TABLE statement to alter a table in Hive.

Syntax

The statement takes any of the following syntaxes based on what attributes we wish to modify in a table.

Few scenarios are explained below.

Rename To… Statement

The following query renames a table from employee to emp.

Change Statement

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 –

Add Columns Statement

The following query adds a column named dept to the employee table.

Replace Statement

Below query deletes all the columns from the employee table and replaces it with emp and name columns –

Drop Table Statement

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

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

HCatalog Topics