hive update delete

原创 2015年07月09日 14:29:05

Hive 从0.14开始支持事务,即支持update和delete操作。事务操作有严格的要求,在写这篇文章时用的1.1.0有以下限制

  1. BEGIN, COMMIT, and ROLLBACK are not yet supported. All language operations are auto-commit. The plan is to support these in a future release.
  2. Only ORC file format is supported in this first release. The feature has been built such that transactions can be used by any storage format that can determine how updates or deletes apply to base records (basically, that has an explicit or implicit row id), but so far the integration work has only been done for ORC.
  3. By default transactions are configured to be off. See the Configuration section below for a discussion of which values need to be set to configure it.
  4. Tables must be bucketed to make use of these features. Tables in the same system not using transactions and ACID do not need to be bucketed.
  5. At this time only snapshot level isolation is supported. When a given query starts it will be provided with a consistent snapshot of the data. There is no support for dirty read, read committed, repeatable read, or serializable. With the introduction of BEGIN the intention is to support snapshot isolation for the duration of transaction rather than just a single query. Other isolation levels may be added depending on user requests.
  6. The existing ZooKeeper and in-memory lock managers are not compatible with transactions. There is no intention to address this issue. See Basic Design below for a discussion of how locks are stored for transactions.

    经过多次试验,才最终实现,具体步骤如下:
    1、设置相关参数

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;

2、创建表

use tmp;
drop table cuixz;
create table cuixz (
log_id int,
agg_status tinyint
)
CLUSTERED BY (log_id) INTO 1 BUCKETS
stored as orc
TBLPROPERTIES ("transactional"="true","NO_AUTO_COMPACTION"="true");  --目前大小写敏感

3、测试

hive> insert into cuixz select log_id, agg_status from stg_dp.s_log_file;

hive> select * from cuixz where log_id = 3480224;
OK
3480224 NULL
Time taken: 0.213 seconds, Fetched: 1 row(s)

hive> update cuixz set agg_status = 1 where log_id = 3480224;

hive> select * from cuixz where log_id = 3480224;
OK
3480224 1
Time taken: 0.144 seconds, Fetched: 1 row(s)
hive> select * from cuixz where log_id = 3480224;

hive>  select * from cuixz where log_id = 3480224;
OK
Time taken: 0.351 seconds

注:update\delete后面的where表达式不支持子查询
参考
https://cwiki.apache.org/confluence/display/Hive/Hive+Transactions
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-Create/Drop/TruncateTable

版权声明:欢迎转载。

相关文章推荐

hive0.14-insert、update、delete操作测试

首先用最普通的建表语句建一个表:

让Hive支持行级insert、update、delete

Hive从0.14版本开始支持事务和行级更新,但缺省是不支持的,需要一些附加的配置。要想支持行级insert、update、delete,需要配置Hive支持事务。 一、Hive具有ACID语义事务...
  • wzy0623
  • wzy0623
  • 2016年05月23日 18:12
  • 10870

开启hive数据表的update delete

之前介绍了hive的安装,hive安装后可以修改建表及查询操作,在执行修改操作时遇到了如下问题。 update student set name='zhangsan' where id=3; FAI...

hive实现update与delete

INSERT OVERWRITE TABLE tablename2 [PARTITION (partcol1=val)] Select * from tablename1 where par...

HIVE中数据更新(update)操作的实现

数据更新是一种常见的操作,然后数据仓库的概念一般要求的是数据是集成、稳定的。HIVE作为一种分布式环境下以HDFS为支撑的数据仓库,它同样更多的要求数据是不可变的。 然而现实很多任务中,往往需要...

hive中的增删改如何实现

由于 Hive 是针对数据仓库应用设计的,而数据仓库的内容是读多写少的。因此,Hive 中不支持对数据的改写和添加,所有的数据都是在加载的时候中确定好的。而数据库中的数据通常是需要经常进行修改的,因此...

hive常用语句

Hive 是基于Hadoop 构建的一套数据仓库分析系统,它提供了丰富的SQL查询方式来分析存储在Hadoop 分布式文件系统中的数据,可以将结构 化的数据文件映射为一张数据库表,并提供完整的SQL...

hive0.14-insert、update、delete操作测

hive0.14-insert、update、delete操作测 http://www.aboutyun.com/thread-12155-1-1.html 首先用最普通的建表语句建一个表...
  • whbo111
  • whbo111
  • 2015年06月18日 16:47
  • 1162

hive如何配置支持事务及insert、update、delete

转载自:http://www.aboutyun.com/forum.php?mod=viewthread&tid=21274&extra=page%3D1 Hive从0.14版本开始支持事务...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:hive update delete
举报原因:
原因补充:

(最多只允许输入30个字)