CDH6.3.1中Hive开启事务机制

       今天在工作中需要在Hive中建立事务表以支持update和delete等操作,这就需要开启Hive的事务机制。在CDH的监控界面,找到Hive的配置,具体操作,请戳这里~。在相关栏目下进行如下设置:

服务端:
hive-site.xml 的 Hive 服务高级配置代码段(安全阀)
hive.txn.manager = org.apache.hadoop.hive.ql.lockmgr.DbTxnManager  
hive.compactor.initiator.on = true  
hive.compactor.worker.threads=1

客户端
hive-site.xml 的 Hive 客户端高级配置代码段(安全阀)
hive.txn.manager = org.apache.hadoop.hive.ql.lockmgr.DbTxnManager 
hive.support.concurrency = true  
hive.enforce.bucketing = true  
hive.exec.dynamic.partition.mode = nonstrict

       设置完成后,我们来进行一下简单的测试。

       1、首先去到Hive的命令行,新建事务表。

create table aaa(id int, name string) clustered by (id) into 2 buckets stored as orc TBLPROPERTIES('transactional'='true');

       2、往测试表中插入几条数据。

insert into table aaa values (1,'xzw'),(2,'yxy'),(3,'lyq');

       3、进行相关的更新删除测试。

delete from aaa where id = 1;
update aaa set name = 'upxzw' where id = 2;

猜你喜欢

转载自blog.csdn.net/gdkyxy2013/article/details/105756793