Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hive 1.1.0 Alter table partition type from int to string

I have a table which has a partition of type int but which I want to convert to string. However, I can't figure out how to do this.

The table description is:

Col1 timestamp
Col2 string
Col3 string
Col4 string
Part_col int

# Partition information
# col_name data_type comment

Part_col int

The partitions I have created are Part_col=0, Part_col=1, ..., Part_col=23

I want to change them to Part_col='0' etc

I run this command in hive:

set hive.exec.dynamic.partitions = true;
Alter table tbl_name partition (Part_col=0) Part_col Part_col string;

I have also tried using "partition (Part_col)" to change all partitions at once.

I get the error "Invalid column reference Part_col"

I am using the example from https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types for conversion of decimal columns but can't figure out what dec_column_name represents.

Thanks

like image 980
Chris Njuguna Avatar asked Jul 17 '15 12:07

Chris Njuguna


People also ask

How do I change the datatype of a Hive table?

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.

Can we change the partition column in Hive?

Unfortunately, given that your data is already partitioned by country, the only option you have is to drop the table, remove the data (supposing your table is external) from the HDFS and reinsert the data using continent as partition.


1 Answers

A bit of digging revealed that there was a hive JIRA to have a command exactly for updating partition column data type (https://issues.apache.org/jira/browse/HIVE-3672)

alter table {table_name} partition column ({column_name} {column_type});

According to JIRA the command was implemented, but it's apparent that it was never documented on Hive Wiki.

I used it on my Hive 0.14 system and it worked as expected.

like image 198
sokhaty Avatar answered Sep 22 '22 21:09

sokhaty