Hive 使用遇到的问题

一、注意事项

  • hive table 读取文件前,默认的分隔符是 \001 (就是 8 进制的 \t)
  • hive table 的分隔符号很重要,在规划文件、建表的时候就要把字段和行的分割符号定义好
  • hive table 在做出导出文件的时候,最好也指定好字段和行的分隔符
  • hive table 有时会使用 sqoop 导入导出数据,注意查看表结构,分隔符指定好给 sqoop

二、HQL 问题

1. 报错找不到类

  1. 问题:
  2. ClassNotFoundException: Class org.apache.hadoop.hive.contrib.serde2.RegexSerDe not found
  3. 解决:
  4. sudo ln -s /opt/cloudera/parcels/CDH-5.3.2-1.cdh5.3.2.p0.10/lib/hive/lib /etc/hive/auxlib
  5. CM配置:
  6. Hive 辅助 JAR 目录:
  7. /etc/hive/auxlib
  8. hive-env.sh Gateway 客户端环境高级配置代码段(安全阀):
  9. HIVE_AUX_JARS_PATH=/etc/hive/auxlib
  10. 参考:
  11. http://blog.csdn.net/sptoor/article/details/9838691
  12. http://blog.csdn.net/xiao_jun_0820/article/details/38302451

2. SerDe 支持 json

  1. 下载包
  2. wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/hive-json-serde/hive-json-serde-0.2.jar
  3. 添加jar
  4. add jar /home/heyuan.lhy/develop/wanke_http_test/hive-json-serde-0.2.jar;
  5. CREATE TABLE test_json (
  6. id BIGINT,
  7. text STRING
  8. ) ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.JsonSerde'
  9. STORED AS TEXTFILE
  10. ;
  11. LOAD DATA LOCAL INPATH "test.json" OVERWRITE INTO TABLE test_json;

3. 第三方类库需要在 beeline 生效

  1. 问题 :
  2. On the Beeline client machine, in /etc/hive/conf/hive-site.xml, set the hive.aux.jars.path property to a comma-separated list of the fully-qualified paths to the JAR file and any dependent libraries.
  3. 解决 :
  4. - 修改配置问题 /etc/hive/conf/hive-site.xml
  5. - 在下次重启时,自动生效
  6. <property>
  7. <name>hive.aux.jars.path</name>
  8. <value>file:///etc/hive/auxlib/hive-json-serde-0.2.jar</value>
  9. </property>
  10. 重启服务
  11. sudo service hive-metastore restart
  12. sudo service hive-server2 restart
  13. sudo service hiveserver restart

4. RegexSerDe 支持正则表达式

  1. 问题:
  2. row format SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
  3. 解决:
  4. add jar hdfs://UCloudcluster/umr-jdlg4d/jars/hive-contrib-0.12.0-cdh5.1.0.jar;

二、 版本升级导致的问题

1、desc table [table name]返回不一致

  • 0.10之前不返回分区信息,0.11和0.12版本强制返回分区信息,并且不可配置。0.13之后可以通过配置设置不返回
  1. Version information partition & non-partition columns
  2. Icon
  3. In Hive 0.10.0 and earlier, no distinction is made between partition columns and non-partition columns while displaying columns for DESCRIBE TABLE. From Hive 0.12.0 onwards, they are displayed separately.
  4. In Hive 0.13.0 and later, the configuration parameter hive.display.partition.cols.separately lets you use the old behavior, if desired (HIVE-6689). For an example, see the test case in the patch for HIVE-6689.

2. hive1.1版本load data问题

  1. LOAD DATA INPATH filepath INTO TABLE xxx, 语句,filepath中的文件如果是(_)或者(.)开头的,将不会被load
  2. * 同样,LOAD DATA INPATH ‘/filepath/filename INTO TABLE xxx, 语句,filename如果是(_)或者(.)开头的,也不会被load

三、Hive 和 HiveServer2 配置问题

1. HiveServer2 使用一段时间后会连接超时,等待时间长

  • 解决
  1. Error when releasing lock 原因可能是 hiveserver2 内存不足,GC或者full GC时间过长
  2. 1. zookeeper 的会话超期
  3. Caused by: org.apache.hadoop.hive.ql.lockmgr.LockException: org.apache.zookeeper.KeeperException$SessionExpiredException: KeeperErrorCode = Session expired for /hive_zookeeper_namespace/default/LOCK-SHARED-0000000000
  4. 2. 紧接着出现OOM异常
  5. ERROR thrift.ProcessFunction (ProcessFunction.java:process(41)) - Internal error processing ExecuteStatement
  6. java.lang.OutOfMemoryError: Java heap space
  7. 目前解决办法:
  8. 1. hive-env.sh
  9. export HADOOP_HEAPSIZE=2048 调整 export HADOOP_HEAPSIZE=3096
  10. 2. hadoop-env.sh
  11. export HADOOP_CLIENT_OPTS="-Xmx6144M -XX:MaxPermSize=512M -Djava.net.preferIPv4Stack=true $HADOOP_CLIENT_OPTS"
  12. 调整配置之后重启服务
  13. sudo service hive-metastore restart
  14. sudo service hive-server2 restart