1. 程式人生 > >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 '\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;