Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change column type in hive

Tags:

hadoop

hive

I just started learning hive yesterday and I am stuck on changing the type of a column in hive. I wanted to ask if the changing of column type has some kind of restriction on them because I can only do specific type of changes like I can convert int to double, string to double, double to string but I cant change string to int, double to int.

ALTER TABLE student CHANGE rollno rollno int;
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Unable to alter table. The following columns have types incompatible with the existing columns in their respective positions :
rollno

hive> DESCRIBE FORMATTED student
> ;
OK
# col_name              data_type               comment             

rollno                  int                                         
name                    string                                      
phno                    string                                      
city                    string   

    ALTER TABLE student CHANGE rollno rollno double;
OK
Time taken: 0.144 seconds

ALTER TABLE student CHANGE rollno rollno int;

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Unable to alter table. The following columns have types incompatible with the existing columns in their respective positions :

rollno

Cant do with strings either. So please guide me towards the answer as I cant seem to find anything through google.

like image 352
Akshansh Jain Avatar asked Apr 25 '16 09:04

Akshansh Jain


People also ask

How do I change the datatype of a column in Hive?

By using this command below one can change the column data type: ALTER TABLE table_name CHANGE column_name column_name new_datatype; I hope this works.

How do I change column sequence in Hive?

This command moves column_name after column_name2: alter table table_name change column column_name column_name column_name_type after column_name2; You have to put the column_name twice (or you can change column name) and type of the column.


1 Answers

If you just want to change the column type,not caring about implicit conversions for example,the old columns type is wrong.

You can try this:

set hive.metastore.disallow.incompatible.col.type.changes=false;
like image 70
xiangya Avatar answered Oct 26 '22 19:10

xiangya