hive-事务

参考:hive-事务支持

  • 背景介绍

在0.13.0版本之前,hive只能进行块级事务的操作,由于hive是基于HDFS的操作,所以都是以块为单位进行存储

继0.13.0版本之后,hive开始支持事务处理,也就是说hive可以支持以行为单位的原子性操作,以及具有acid的特性(atmoic原子性 consistency 一致性 isolation 隔离性 durability 永久性)

  • hive配置

(1)表的类型:桶表

(2)表的存储类型;ORC (optimized row columna)优化列模式文件 ,ep:stored as orc

(3)在建表的最后加上 tblproperties('transactional'='true');

  (4)   配置hive-site.xml参数

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

(1)创建桶表(注意这里不能在hive默认的数据库中default使用事务操作,否则插入数据的时候会报错)

hive> create table t1(id int,name string) clustered by (id) into 2 buckets
    > row format delimited
    > fields terminated by '	'
    > lines terminated by '
'
    > stored as orc
    > tblproperties('transactional'='true');

(2)插入数据,更新数据都是OK的

hive> insert into t1 values(1,'aa');
hive> update t1 set name = 'bb' where id  = 1;
hive> delete from t1 where id =1;
欢迎关注我的公众号:小秋的博客 CSDN博客:https://blog.csdn.net/xiaoqiu_cr github:https://github.com/crr121 联系邮箱:rongchen633@gmail.com 有什么问题可以给我留言噢~
原文地址:https://www.cnblogs.com/flyingcr/p/10326853.html