Search code examples
hivealterorc

Renaming Column names in hive ORC table is resulting in NULL values in the New column


I´m trying to rename the column name in hive (ORC table) table using alter command. Columns are getting renamed however data is getting modified to Null values.

Example:

select city from p_details;

city

Santa Fe Springs
Jiangmen

**alter table p_details change city city_name string;**

select city_name from p_details;

city_name

NULL
NULL

Solution

  • According to Hive manual: "The column change command will only modify Hive's metadata, and will not modify data. Users should make sure the actual data layout of the table/partition conforms with the metadata definition.", which implies that the column change will not change any underlying data if it is an orc or parquet table. Try to execute msck repair table <table_name>, but it may not help.

    You can always create a new table with renamed column.