Currently, I try to union several tables in hive. After I achieved this, I found that some column type is not proper. I thought some should be float
but some kind it becomes string
. Then I ran alter command:alter table table_name change column_name column_name float;
It returned error message:
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
I thought this means that hive don't support convert string to float as showed in table. But I found that I can do cast on the same column and get wanted result. This makes me confused why there will be different result between alter and cast. What is the logic behind it. THX.
It seems you have missed CHANGE keyword.
See here: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-ChangeColumnName/Type/Position/Comment
Demo: