Hive的行级acid事务处理

//事务,hive 0.13.0之后完全支持行级acid事务处理。
//所有事务都是自动提交,并且存储文件只能是orc文件,而且只能在桶表中使用。
1.设置相关属性
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;

2.显式事务命令:
SHOW TRANSACTIONS;

3.操作语法
INSERT INTO TABLE tablename [PARTITION (partcol1[=val1], partcol2[=val2]...)] VALUES values_row [, values_row …];
UPDATE tablename SET column = value [, column = value…] [WHERE expression]
DELETE FROM tablename [WHERE expression]

4.创建表时,使用桶表,orc文件格式,支持事务的属性
create table tx(id int ,name string , age int)
clustered by (id) into 2 buckets
stored as orc
TBLPROPERTIES('transactional'='true');

5.执行操作
insert into tx(id,name,age) values(1,'tom',2) ;
update tx set name = 'tomas' where id = 1 ;
delete from tx where id =1 ;

你可能感兴趣的:(Hive实战)