开启hive数据表的update delete

之前介绍了hive的安装,hive安装后可以修改建表及查询操作,在执行修改操作时遇到了如下问题。

update student set name='zhangsan' where id=3;
FAILED: SemanticException [Error 10294]: Attempt to do update or delete using transaction manager that does not support these operations.
经过几番周折终于找到了解决方案。

1,在hive-site.xml文件中,增加如下属性。


    hive.support.concurrency
    true
  
    
    hive.enforce.bucketing
    true
  
    
    hive.exec.dynamic.partition.mode
    nonstrict
  
  
    hive.txn.manager
    org.apache.hadoop.hive.ql.lockmgr.DbTxnManager
  
    
    hive.compactor.initiator.on
    true
  
  
    hive.compactor.worker.threads
    1
  
  
	hive.in.test
	true
  

2,重启hive服务;

3,采用如下语句创建表;

create table student(
  id int,
  name String,
  sex varchar(2),
  birthday varchar(10),
  major varchar(1)
)clustered by (id) into 2 buckets stored as orc TBLPROPERTIES('transactional'='true');

4,测试update,delete语句

hive> update student set name='zhangsan' where id=3;
WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
Query ID = hadoop_20160417181258_c96e1b21-3832-4127-af01-62e0910fd9f3
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks determined at compile time: 2
In order to change the average load for a reducer (in bytes):
  set hive.exec.reducers.bytes.per.reducer=
In order to limit the maximum number of reducers:
  set hive.exec.reducers.max=
In order to set a constant number of reducers:
  set mapreduce.job.reduces=
Starting Job = job_1460881375700_0012, Tracking URL = http://master:8088/proxy/application_1460881375700_0012/
Kill Command = /home/hadoop/bigdata/hadoop-2.7.1/bin/hadoop job  -kill job_1460881375700_0012
Hadoop job information for Stage-1: number of mappers: 2; number of reducers: 2
2016-04-17 18:13:05,954 Stage-1 map = 0%,  reduce = 0%
2016-04-17 18:13:12,556 Stage-1 map = 50%,  reduce = 0%, Cumulative CPU 1.55 sec
2016-04-17 18:13:13,613 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 3.17 sec
2016-04-17 18:13:17,977 Stage-1 map = 100%,  reduce = 50%, Cumulative CPU 4.38 sec
2016-04-17 18:13:20,079 Stage-1 map = 100%,  reduce = 100%, Cumulative CPU 6.38 sec
MapReduce Total cumulative CPU time: 6 seconds 380 msec
Ended Job = job_1460881375700_0012
Loading data to table default.student
MapReduce Jobs Launched: 
Stage-Stage-1: Map: 2  Reduce: 2   Cumulative CPU: 6.38 sec   HDFS Read: 30517 HDFS Write: 1022 SUCCESS
Total MapReduce CPU Time Spent: 6 seconds 380 msec
OK
Time taken: 24.301 seconds


修改成功啦。


你可能感兴趣的:(hive)