0

Can we drop multiple columns in a single Alter statement in Hive.

Something like

Alter table t drop column a1,a2 

I have to drop around 7 columns , so was looking for an elegant method

av abhishiek
  • 647
  • 2
  • 11
  • 26

1 Answers1

1

I don't have experience in the hive, But My findings may help you!.

It seems, We cannot drop column directly from a table using command ALTER TABLE table_name drop col_name;

So provide all those columns which you want to be the part of table in replace columns clause. For Example, the emp table contains following columns Id, Name, Dept, Email, Address, Salary and if we want to remove the Address and Salary column, then the query would be like following

ALTER TABLE emp REPLACE COLUMNS( Id int, Name string, Dept string, Email string);

NOTE: However Above statement can only change the schema of a table, not data.

like the way you should mention all the columns (which is you want to keep in table) in REPLACE clause.

Referred from here & here

Kavin
  • 303
  • 2
  • 14