CDH Hive行级更新操作--实现update和delete

本文介绍了在CDH环境下,如何配置Hive以支持update和delete操作,包括设置客户端和服务端的配置参数。在遇到错误10294和10297时,解析了问题原因并提供了解决方案,强调了表需要使用ORC存储格式,进行分桶,并设置transactional属性为true。最后展示了修改建表语句以启用ACID特性的例子。
摘要由CSDN通过智能技术生成

一、问题出现原因

在Hive表执行update和delete操作时,报如下错误:

FAILED: SemanticException [Error 10294]: Attempt to do update or delete using transaction manager that does not support these operations.

如图所示:

经过查阅资料发现,要实现update和delete操作,需要开启事务功能,详细见官网:https://cwiki.apache.org/confluence/display/Hive/Hive+Transactions#HiveTransactions-NewConfigurationParametersforTransactions
在Configuration配置有详细的操作,如图所示:

Minimally, these configuration parameters must be set appropriately to turn on transaction support in Hive:

Client Side

hive.support.concurrency – true
hive.enforce.bucketing – true (Not required as of Hive 2.0)
hive.exec.dynamic.partition.mode – nonstrict
hive.txn.manager – org.apache.hadoop.hive.ql.lockmgr.DbTxnManager
Server Side (Metastore)

hive.compactor.initiator.on – true (See table below for more details)
hive.compactor.worker.threads – a positive number on at least one instance of the Thrift metastore service
The following sections list all of the configuration parameters that affect Hive transactions and compaction.  Also see Limitations above and Table Properties below.

二、CDH详细操作配置

2.1 hive --> 配置 --> 搜索 hive-site

2.2 修改服务的和客户端的配置

服务端配置
<property>
	<name>hive.compactor.initiator.on</name>
	<value>true</value>
</property>
<property>
	<name>hive.compactor.worker.threads </name>
	<value>1</value>
</property>

客户端配置
<property>
	<name>hive.support.concurrency</name>
	<value>true</value>
</property>
<property>
	<name>hive.enforce.bucketing</name>
	<value>true</value>
</property>
<property>
	<name>hive.exec.dynamic.partition.mode</name>
	<value>nonstrict</value>
</property>
<property>
	<name>hive.txn.manager</name>
	<value>org.apache.hadoop.hive.ql.lockmgr.DbTxnManager</value>
</property>

修改后如下图所示:

修改完配置保存后,需要重启集群

重启Hive后,也需要重新启动客户端进行操作,重新执行以下update操作,却发现报以下错误:

hive> update t_user set name='aaa' where id=1;
FAILED: SemanticException [Error 10297]: Attempt to do update or delete on table test.t_user that does not use an AcidOutputFormat or is not bucketed

如图所示:

解决方法:
如果一个表要实现update和delete功能,该表就必须支持ACID,而支持ACID,就必须满足以下条件:

	1.表的存储格式必须是ORC(STORED AS ORC);
	2.表必须进行分桶(CLUSTERED BY (col_name, col_name, …) INTO num_buckets BUCKETS);
	3.Table property中参数transactional必须设定为True(tblproperties(‘transactional’=‘true’));

然后修改建表语句:

create table if not exists t_user1 (
  id int,
  name string
) COMMENT '用户表'
clustered by (id) into 2 buckets
row format delimited fields terminated by '|'
stored as orc TBLPROPERTIES('transactional'='true')

执行操作:

insert into t_user1 values(1,'qwr');
update t_user1 set name='qaz' where id=1;
delete from t_user1 where id=1;

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CDH(Cloudera's Distribution Including Apache Hadoop)是基于Apache Hadoop的分布式计算平台。CDH Hive驱动是CDH平台上的一种驱动程序,用于连接和操作Hive数据库。 Hive是一个基于Hadoop的数据仓库工具,它提供了类似于SQL的查询语言(HiveQL),使用户可以进行数据分析和查询。Hive将用户提交的HiveQL查询转换为MapReduce任务,并在Hadoop集群上执行这些任务。CDH Hive驱动提供了与Hive数据库的连接和操作功能。 使用CDH Hive驱动,用户可以通过CDH平台访问和操作Hive数据库中的数据。用户可以使用HiveQL查询语言编写复杂的查询,并将其提交给CDH Hive驱动执行。驱动程序会将查询转换为MapReduce任务,并在Hadoop集群上运行这些任务。查询结果可以以各种格式返回给用户,例如表格、文件或视图。 CDH Hive驱动具有以下特点和优势: 1. 强大的数据处理能力:借助HiveQL语言和MapReduce任务执行,CDH Hive驱动可以高效地处理大规模数据集,支持复杂的数据仓库操作和查询。 2. 高度可扩展:CDH平台基于Hadoop的分布式架构,CDH Hive驱动可以利用Hadoop集群的并行计算和存储能力,实现高度可扩展的数据处理能力。 3. 多种数据格式支持:CDH Hive驱动支持多种数据格式,如文本、CSV、JSON等,方便用户根据不同的需求进行数据存储和查询。 4. 丰富的生态系统支持:CDH平台提供了丰富的周边工具和组件,如Impala、Spark等,CDH Hive驱动可以与这些工具进行集成,提供更多的数据处理能力和灵活性。 总之,CDH Hive驱动是CDH平台上与Hive数据库连接和操作的重要组件,通过使用CDH Hive驱动,用户可以在CDH平台上高效地处理和查询大规模的数据集。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值