javier_orta
javier_orta

Reputation: 477

How to update some rows in a partitioned table in hive?

I need to update some rows in a partitioned table by date, with a ranges of dates and i don't know how to do it?

Upvotes: 2

Views: 1155

Answers (1)

leftjoin
leftjoin

Reputation: 38335

Using dynamic partitioning you can overwrite partitions which is necessary to update. Use case statement to check for rows to be modified and to set values, like in this template:

set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;

insert overwrite table table_name partition (partition_column)

select col1, 
       col2,
       case when col1='record to be updated' then 'new value' else col3 end as col3,
       ...
       colN,
       partition_column --partition_column should be the last
from table_name 
where ...--partition predicate here

Upvotes: 2

Related Questions