Change Column Position – Apache Impala & Apache Hive

Previous articles described how to insert columns between existing table columns in various RDBMSs. Currently, Apache Impala does not support this. You can, however, change the position of a column using Apache Hive once it has been added. It’s a workaround, though.

Let’s see it practically.

Go to Impala and create a test table.
CREATE TABLE Test1(Col1 INT, Col3 String, Col2 String);

When you look at the columns, you’ll notice that I put Col3 before Col2. The position of Col3 and Col2 must now be changed.

Impala_table_create_for_col-positioning

Now, go to Hive, and change the position using the below command.
ALTER TABLE Test1 CHANGE COLUMN Col3 Col3 String AFTER Col2;

The syntax of the above command is-
ALTER TABLE tab CHANGE COLUMN existing_col existing_col string AFTER column_name;

hive_for_col-positioning

Hope you find this article helpful.

Please subscribe for more interesting updates.

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