🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
**1. 通过命令行方式开启事务,当前session有效** ```sql 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; ``` <br/> **2. 通过配置文件hive-site.xml** ```xml <property> <name>hive.support.concurrency</name> <value>true</value> </property> <property> <name>hive.txn.manager</name> <value>org.apache.hadoop.hive.ql.lockmgr.DbTxnManager</value> </property> ``` <br/> **3. 通过UI工具(如Ambari)设置** ![](https://img.kancloud.cn/bf/de/bfde96cf61759eb0ad907cbe7d969631_406x521.png) <br/> 按照上面的方式之一开启Hive事务后,创建如下的支持事务的分桶表: ```sql create table dim_Product ( product_sk int , product_code int , product_name varchar(128), product_category varchar(256), version varchar(32), effective_date date, expiry_date date ) -- 在Hive中只有分桶表支持事务 clustered by (product_sk ) into 8 buckets -- 设置属性transactional'='true'开启事务支持 stored as orc tblproperties('transactional'='true'); ```