当前位置:   article > 正文

Hive实现delete、update操作_hive delete

hive delete
Hive在默认情况下是没有办法进行update、delete的,
但是我们可以通过以下方式实现 行级别&批量级 的delete、update
  • 1
  • 2

行级别delete、update

• 只支持ORC存储格式
• 表必须分桶
• 更新指定配置文件
  • 1
  • 2
  • 3
1.创建ORC存储格式、且分桶的表
  • 1
CREATE TABLE table_name (
id int,
name string
)CLUSTERED BY (id) INTO 2 BUCKETS STORED AS ORC
TBLPROPERTIES ("transactional"="true");
--transactional:交易型的;事务性的;事务处理的
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
2.修改添加hive中的hive-site.xml配置文件
  • 1
<property>
    <name>hive.support.concurrency</name>
    <value>true</value>
</property>
<property>
    <name>hive.enforce.bucketing</name>
    <value>true</value>
</property>
<property>
    <name>hive.exec.dynamic.partition.mode</name>
    <value>nonstrict</value>
</property>
<property>
    <name>hive.txn.manager</name>
    <value>org.apache.hadoop.hive.ql.lockmgr.DbTxnManager</value>
</property>
<property>
    <name>hive.compactor.initiator.on</name>
    <value>true</value>
</property>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

批量级delete、update

分区表

-- delete 操作 就是删除指定分区
alter table drop if exists partition(xxx);

-- update 操作 就是先删除再加载
insert overwrite table xxx partition(xxx);
--或者
load data inpath 'xxx' overwrite into table partition(xxx);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

非分区表

-- delete 操作 将除了“条件”外的数据覆盖本表
insert overwrite table xxx select * from xxx where dt != '20221010';

-- update 操作 依旧是先执行上述的删除操作再进行插入操作
insert overwrite table xxx select * from xxx where dt != '20221010';
insert into table xxx values(......);
--或者
load data inpath into table xxx;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/798490
推荐阅读
相关标签
  

闽ICP备14008679号