Hive的行級acid事務處理
阿新 • • 發佈:2019-02-05
//事務,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 ;
//所有事務都是自動提交,並且儲存檔案只能是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 ;