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.
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.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With