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 '\t'
        > lines terminated by '\n'
        > 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;

 
 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值