FROM : http://blog.csdn.net/hi_box/article/details/40820341

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

  1. hive>create table test(id int,name string)row format delimited fields terminated by ',';

测试insert:

  1. insert into table test values (1,'row1'),(2,'row2');

结果报错:

  1. java.io.FileNotFoundException: File does not exist: hdfs://127.0.0.1:9000/home/hadoop/git/hive/packaging/target/apache-hive-0.14.0-SNAPSHOT-bin/
  2. apache-hive-0.14.0-SNAPSHOT-bin/lib/curator-client-2.6.0.jar
  3. at org.apache.hadoop.hdfs.DistributedFileSystem$17.doCall(DistributedFileSystem.java:1128)
  4. at org.apache.hadoop.hdfs.DistributedFileSystem$17.doCall(DistributedFileSystem.java:1120)
  5. at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)
  6. at org.apache.hadoop.hdfs.DistributedFileSystem.getFileStatus(DistributedFileSystem.java:1120)
  7. at org.apache.hadoop.mapreduce.filecache.ClientDistributedCacheManager.getFileStatus(ClientDistributedCacheManager.java:288)
  8. at org.apache.hadoop.mapreduce.filecache.ClientDistributedCacheManager.getFileStatus(ClientDistributedCacheManager.java:224)
  9. at org.apache.hadoop.mapreduce.filecache.ClientDistributedCacheManager.determineTimestamps(ClientDistributedCacheManager.java:99)
  10. at org.apache.hadoop.mapreduce.filecache.ClientDistributedCacheManager.determineTimestampsAndCacheVisibilities(ClientDistributedCacheManager.java:57)
  11. at org.apache.hadoop.mapreduce.JobSubmitter.copyAndConfigureFiles(JobSubmitter.java:265)
  12. at org.apache.hadoop.mapreduce.JobSubmitter.copyAndConfigureFiles(JobSubmitter.java:301)
  13. at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:389)
  14. at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1285)
  15. at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1282)
  16. at java.security.AccessController.doPrivileged(Native Method)
  17. ......

貌似往hdfs上找jar包了,小问题,直接把lib下的jar包上传到hdfs

  1. hadoop fs -mkdir -p /home/hadoop/git/hive/packaging/target/apache-hive-0.14.0-SNAPSHOT-bin/apache-hive-0.14.0-SNAPSHOT-bin/lib/
  2. hadoop fs -put $HIVE_HOME/lib/* /home/hadoop/git/hive/packaging/target/apache-hive-0.14.0-SNAPSHOT-bin/apache-hive-0.14.0-SNAPSHOT-bin/lib/

接着运行insert,没有问题,接下来测试delete

  1. hive>delete from test where id = 1;

报错!:

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

说是在使用的转换管理器不支持update跟delete操作。

原来要支持update操作跟delete操作,必须额外再配置一些东西,见:

https://cwiki.apache.org/confluence/display/Hive/Hive+Transactions#HiveTransactions-NewConfigurationParametersforTransactions

根据提示配置hive-site.xml:

  1. hive.support.concurrency – true
  2. hive.enforce.bucketing – true
  3. hive.exec.dynamic.partition.mode – nonstrict
  4. hive.txn.manager – org.apache.hadoop.hive.ql.lockmgr.DbTxnManager
  5. hive.compactor.initiator.on – true
  6. hive.compactor.worker.threads – 1

配置完以为能够顺利运行了,谁知开始报下面这个错误:

  1. FAILED: LockException [Error 10280]: Error communicating with the metastore

与元数据库出现了问题,修改log为DEBUG查看具体错误:

  1. 2014-11-04 14:20:14,367 DEBUG [Thread-8]: txn.CompactionTxnHandler (CompactionTxnHandler.java:findReadyToClean(265)) - Going to execute query <select cq_id,
  2. cq_database, cq_table, cq_partition, cq_type, cq_run_as from COMPACTION_QUEUE where cq_state = 'r'>
  3. 2014-11-04 14:20:14,367 ERROR [Thread-8]: txn.CompactionTxnHandler (CompactionTxnHandler.java:findReadyToClean(285)) - Unable to select next element for cleaning,
  4. Table 'hive.COMPACTION_QUEUE' doesn't exist
  5. 2014-11-04 14:20:14,367 DEBUG [Thread-8]: txn.CompactionTxnHandler (CompactionTxnHandler.java:findReadyToClean(287)) - Going to rollback
  6. 2014-11-04 14:20:14,368 ERROR [Thread-8]: compactor.Cleaner (Cleaner.java:run(143)) - Caught an exception in the main loop of compactor cleaner, MetaException(message
  7. :Unable to connect to transaction database com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hive.COMPACTION_QUEUE' doesn't exist
  8. at sun.reflect.GeneratedConstructorAccessor19.newInstance(Unknown Source)
  9. at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  10. at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
  11. at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)

在元数据库中找不到COMPACTION_QUEUE这个表,赶紧去mysql中查看,确实没有这个表。怎么会没有这个表呢?找了很久都没找到什么原因,查源码吧。

在org.apache.hadoop.hive.metastore.txn下的TxnDbUtil类中找到了建表语句,顺藤摸瓜,找到了下面这个方法会调用建表语句:

  1. private void checkQFileTestHack() {
  2. boolean hackOn = HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_IN_TEST) ||
  3. HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_IN_TEZ_TEST);
  4. if (hackOn) {
  5. LOG.info("Hacking in canned values for transaction manager");
  6. // Set up the transaction/locking db in the derby metastore
  7. TxnDbUtil.setConfValues(conf);
  8. try {
  9. TxnDbUtil.prepDb();
  10. } catch (Exception e) {
  11. // We may have already created the tables and thus don't need to redo it.
  12. if (!e.getMessage().contains("already exists")) {
  13. throw new RuntimeException("Unable to set up transaction database for" +
  14. " testing: " + e.getMessage());
  15. }
  16. }
  17. }
  18. }

什么意思呢,就是说要运行建表语句还有一个条件:HIVE_IN_TEST或者HIVE_IN_TEZ_TEST.只有在测试环境中才能用delete,update操作,也可以理解,毕竟还没有开发完全。

终于找到原因,解决方法也很简单:在hive-site.xml中添加下面的配置:

  1. <property>
  2. <name>hive.in.test</name>
  3. <value>true</value>
  4. </property>

OK,再重新启动服务,再运行delete:

  1. hive>delete from test where id = 1;

又报错:

  1. FAILED: SemanticException [Error 10297]: Attempt to do update or delete on table default.test that does not use an AcidOutputFormat or is not bucketed

说是要进行delete操作的表test不是AcidOutputFormat或没有分桶。估计是要求输出是AcidOutputFormat然后必须分桶

网上查到确实如此,而且目前只有ORCFileformat支持AcidOutputFormat,不仅如此建表时必须指定参数('transactional' = true)。感觉太麻烦了。。。。

于是按照网上示例建表:

  1. hive>create table test(id int ,name string )clustered by (id) into 2 buckets stored as orc TBLPROPERTIES('transactional'='true');

insert

  1. hive>insert into table test values (1,'row1'),(2,'row2'),(3,'row3');

delete

  1. hive>delete from test where id = 1;

update

  1. hive>update test set name = 'Raj' where id = 2;

OK!全部顺利运行,不过貌似效率太低了,基本都要30s左右,估计应该可以优化,再研究研究

最后还有个问题:show tables时报错:

  1. hive> show tables;
  2. OK
  3. tab_name
  4. Failed with exception java.io.IOException:java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: fcitx-socket-:0
  5. Time taken: 0.064 seconds

好像跟/tmp/下fcitx-socket-:0文件名有关,待解决。。。

[转] hive0.14-insert、update、delete操作测试的更多相关文章

  1. [Hive - LanguageManual] DML: Load, Insert, Update, Delete

    LanguageManual DML Hive Data Manipulation Language Hive Data Manipulation Language Loading files int ...

  2. 关于MyBatis mapper的insert, update, delete返回值

    这里做了比较清晰的解释: http://mybatis.github.io/mybatis-3/java-api.html SqlSession As mentioned above, the Sql ...

  3. PHP5: mysqli 插入, 查询, 更新和删除 Insert Update Delete Using mysqli (CRUD)

    原文: PHP5: mysqli 插入, 查询, 更新和删除  Insert Update Delete Using mysqli (CRUD) PHP 5 及以上版本建议使用以下方式连接 MySQL ...

  4. mysql 事务是专门用来管理insert,update,delete语句的,和select语句一点不相干

    1.mysql 事务是专门用来管理insert,update,delete语句的,和select语句一点不相干 2.一般来说,事务是必须满足4个条件(ACID): Atomicity(原子性).Con ...

  5. insert update delete 语法 以及用法

    insert update delete 被称为 数据定义语句语句 也就是数据的增加 修改 删除 其中不包括查询 譬如: create database -创建数据库 alter database - ...

  6. sql中同一个Trigger里同时包含Insert,Update,Delete

    sql中同一个Trigger里同时包含Insert,Update,Delete SQLServer是靠Inserted表和Deleted表来处理的,判断一下就可以了,只不过比ORACLE麻烦一点 cr ...

  7. mybatis select/insert/update/delete

    这里做了比较清晰的解释: http://mybatis.github.io/mybatis-3/java-api.html SqlSession As mentioned above, the Sql ...

  8. mysql数据恢复 insert\update\delete 工具MyFlash

    一.简介MyFlash是由美团点评公司技术工程部开发维护的一个回滚DML操作的工具.该工具通过解析v4版本的binlog,完成回滚操作.相对已有的回滚工具,其增加了更多的过滤选项,让回滚更加容易. 该 ...

  9. LINQ体验(9)——LINQ to SQL语句之Insert/Update/Delete操作

    我们继续讲解LINQ to SQL语句,这篇我们来讨论Insert/Update/Delete操作.这个在我们的程序中最为常用了.我们直接看例子. Insert/Update/Delete操作 插入( ...

  10. mybatis insert update delete返回都是整型 0,1,增,删,改要提交事物

    mybatis insert update delete返回都是整型 0,1, 没有扔 增,删,改要提交事物

随机推荐

  1. P1006 传纸条 多维DP

    题目描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个mm行nn列的矩阵,而小渊和小轩被安排在矩阵对角线的两端,因此,他们就无法直接交谈了.幸运 ...

  2. 【Java】 大话数据结构(18) 排序算法(5) (直接插入排序)

    本文根据<大话数据结构>一书,实现了Java版的直接插入排序. 更多:数据结构与算法合集 基本概念 直接插入排序思路:类似扑克牌的排序过程,从左到右依次遍历,如果遇到一个数小于前一个数,则 ...

  3. 015 jquery中包裹节点

    1.介绍 2.程序 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...

  4. 本机Tomcat启动myeclipse,用Jmeter录制脚本端口冲突解决办法

    今天用jmeter 录制脚本与已经启动的Tomcat端口冲突,无法启动工作台的http代理服务器, 如果两个的端口一样,则http代理服务器启动就会提示端口被占用 所以先把Tomcat端口和http代 ...

  5. 一个ScheduledExecutorService启动的Java线程无故挂掉引发的思考

    2018年12月12日18:44:53 一个ScheduledExecutorService启动的Java线程无故挂掉引发的思考 案件现场 不久前,在开发改造公司一个端到端监控日志系统的时候,出现了一 ...

  6. 【Ray Tracing in One Weekend 超详解】 光线追踪1-4

    我们上一篇写了Chapter5 的第一个部分表面法线,那么我们来学剩下的部分,以及Chapter6. Chapter5:Surface normals and multiple objects. 我们 ...

  7. python异常装饰器--比较全的版本了

    # 异常捕获装饰器(亦可用于类方法) def try_except_log(f=None, max_retries: int = 5, delay: (int, float) = 1, step: ( ...

  8. 基于SOA的银行系统架构

    Part-1  [简述] 1.通过引入面向服务架构(SOA),企业服务总线(ESB),适配器(Adapter)及面向构件等技术,尝试打造一个统一业务流程服务平台,实现面向流程的服务集成. 2.传统银行 ...

  9. Win10 主题 美化 动漫

    韩梦飞沙 yue31313 韩亚飞 han_meng_fei_sha  313134555@qq.com High School D×D 塔城白音Win7主题+Win8主题+Win10主题 Win10 ...

  10. hdu 4417 区间内比h小的数 划分树

    二分查找最近一个比h小的数 #include<cstdio> #include<iostream> #include<algorithm> #include< ...