Hive修改分区表数据

时间:2017-01-24 05:18:36

标签: hadoop hive

问题:一列值为空。它应该是'ab'。不幸的是我写了''而不是'ab'。

我的表是分区表。有没有办法改变它?

我发现了以下方式。但这似乎效率低下。

  1. 像我的表一样创建一个临时表
  2. 使用INSERT OVERWRITE。从我的旧表中读取数据并写入新表。我使用case语句将''更改为'ab'
  3. 然后将我的临时表更改为原始表。
  4. 我正在寻找像更新分区和msck这样的解决方案。有什么办法吗?

2 个答案:

答案 0 :(得分:0)

一种可能的解决方案是在表格上执行update,前提是该列既不是分区也不是分段列。

UPDATE tablename SET column = (CASE WHEN column = '' THEN 'ab' else column END) [WHERE expr if any];

更新:支持Hive上的ACID操作

SET hive.support.concurrency=true;
SET hive.enforce.bucketing=true;
SET hive.exec.dynamic.partition.mode=nonstrict;
SET hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
SET hive.compactor.initiator.on=true;
SET hive.compactor.worker.threads=1;

注意:仅在Hive> = 0.14

时有效

答案 1 :(得分:0)

您可以这种方式覆盖单个分区:

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

insert overwrite target_table partition (part_col)
select 
case when column ='' then 'ab' else column end as column ,
col2,    --select all the columns in the same order
col3,
part_col --partition column is the last one
from target_table where part_col='your_partition_value';