2
votes

Referring to ALTER TABLE CHANGE COLUMN documentation here, The PARTITION clause is available in Hive 0.14 and CASCADE is available in Hive 1.1.0

Is it possible to update column type for all partitions in Hive 0.13 ? Without the PARTITION or CASCADE being available, i'm looking of finding a workaround for Hive 0.13

I want to run this command on Hive 0.13:

ALTER TABLE my_table CHANGE COLUMN existing_column new_column STRING
CASCADE;

But CASCADE is not available. I would loop over using PARTITION but PARTITION is also available in 0.14 :(

1

1 Answers

0
votes

There are multiple ways you can fix this problem.

1) Your table is partitioned that means each existing partition also needs to be updated with new column type. You can do this by setting up below property and then run alter statement.

SET hive.exec.dynamic.partition = true;
ALTER TABLE table_name PARTITION (partition_column) 
CHANGE COLUMN old_col new_col data_type;

This property will enable dynamic partitioning that means alter statement will change all partitions.

2) You can also do this by doing 1 partition at a time, just pass the partition key from your script and run ALTER statement for all your partitions. In this case statement will be like:

ALTER TABLE table_name PARTITION (partition_column='value') 
CHANGE COLUMN old_col new_col data_type;

If you want to do it the way Hive 0.14+ supports then you can apply the patch from below link. https://issues.apache.org/jira/browse/HIVE-7971

You can also find all these details in Hive Documentation.