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.
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;
Hope you find this article helpful.
Please subscribe for more interesting updates.