Hive实战9---更新、删除操作

本文介绍如何在Hive中启用事务支持,并通过具体步骤演示如何创建支持事务的表、进行数据插入、更新和删除操作。文章还详细说明了在遇到特定错误时如何调整Hive的配置。
1、创建表:
create table users2(id int,name string)clustered by (id) into 1 buckets stored as orc tblproperties('transactional'='true');
2、插入数据
insert into users2(1,'ZHANGSAN'),(2,'LISI');
3、更新数据
update users2 set name='zhangsan2' where id=1;
报错:
FAILED: SemanticException [Error 10294]: Attempt to do update or delete using transaction manager that does not support these operations.
4、更改设置:
客户端:
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;
服务器端:
更改hive-site.xml,增加如下属性:
<property>
<name>hive.compactor.initiator.on</name>
<value>true</value>
</property>
<property>
<name>hive.compactor.worker.threads</name>
<value>1</value>
</property>
5、退出hive客户端,重新进入
6、执行更新操作
7、删除操作
delete from users2 where id=1;

7 - 2 Hive表DDL操作(二)包含实战简介、全部任务以及实践详解等内容。实践详解分为两个关卡,第1关是Create/Drop/Alter视图,第2关是Create/Drop/ALTER索引 [^1]。 在具体操作方面,有对数据库进行相应操作的示例,如创建数据库、表,加载数据,创建和删除索引等。示例代码如下: ```bash #********* Begin *********# echo " CREATE DATABASE IF NOT EXISTS test2 LOCATION &#39;/hive/test2&#39; WITH DBPROPERTIES(&#39;creator&#39;=&#39;John&#39;,&#39;date&#39;=&#39;2019-02-25&#39;); CREATE TABLE IF NOT EXISTS test2.student( Sno INT COMMENT &#39;student sno&#39;, name STRING COMMENT &#39;student name&#39;, age INT COMMENT &#39;student age&#39;, sex STRING COMMENT &#39;student sex&#39;, score STRUCT<Chinese:FLOAT,Math:FLOAT,English:FLOAT> COMMENT &#39;student score&#39;) COMMENT &#39;students information table&#39; row format delimited fields terminated by &#39;,&#39; collection items terminated by &#39;-&#39; TBLPROPERTIES (&#39;creator&#39;=&#39;John&#39;,&#39;date&#39;=&#39;2019-02-25&#39;); load data local inpath &#39;/home/student.txt&#39; overwrite into table student; create index student_index on table student(Sno) as &#39;org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler&#39; with deferred rebuild IN TABLE student_index_table; drop index if exists student_index on student; " #********* End *********# ``` 这段代码实现了创建名为test2的数据库,创建名为student的表,将本地文件`/home/student.txt`的数据加载到student表中,创建student表的索引student_index,最后删除该索引 [^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

登峰大数据

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值