您好,欢迎访问一九零五行业门户网

Hive 常见问题与技巧

1q: 是否有像类于phpmyadmin一样的hive查询客户端,能以界面的方式查询hive语句和导出数据 a: 有的,客户端的话可以使用squirrel来连接hive,squirrel是一个通用的数据库查询客户端,还有有一个开源项目phphiveadmin也不错, web方式访问hive,这里也有一个h
1q: 是否有像类似于phpmyadmin一样的hive查询客户端,能以界面的方式查询hive语句和导出数据
a: 有的,客户端的话可以使用squirrel来连接hive,squirrel是一个通用的数据库查询客户端,还有有一个开源项目phphiveadmin也不错,
web方式访问hive,这里也有一个hive web client(https://github.com/lalaguozhe/hiveweb-1)
2q: 执行语句时候,能否控制reducer的个数
a: 可以在执行hive语句之前先 set mapred.reduce.tasks=
3q: 是否可能在输出的时候在结果第一行打印列名
a: 可以在执行hive语句之前先 set hive.cli.print.header=true;
4q: hive是否支持跨数据库查询,比如database arch的table1和database algo的table2 进行join
a: 可以,只要有用户有这两张表的select权限即可,用户需要用“database.table”的方式来指定数据库下的表
5q: hive是否有内置的函数,可以对输出的数据进行处理
a: hive提供了丰富的内置函数,参见https://cwiki.apache.org/hive/languagemanual-udf.html,
用户也可以自己实现自定义的udf方法来满足更复杂的查询需求
6q: hive支持exist in么?
a: 不支持,但是可以通过改写语句达到相同的效果,比如对于查询语句:
select a.key, a.value from a where a.key in (select b.key from b);
可以改写成:
select a.key, a.val
from a left semi join b on (a.key = b.key)
ps:上述答案过时了,目前 hive 已经支持 in 查询了。
http://blog.csdn.net/yfkiss/article/details/8073608
7q:hive是否支持本地执行模式
a:hive支持本地执行模式,当数据量小的时候,本地执行比提交到集群上执行效率提升很大
set hive.exec.mode.local.auto=true(默认false)
当一个job满足如下条件才能真正使用本地模式:
1.job的输入数据大小必须小于参数hive.exec.mode.local.auto.inputbytes.max(默认值128mb)
2.job的map处理的文件数大于参数hive.exec.mode.local.auto.input.files.max(默认值4)
3.job的reduce数必须为0或者1,不管是用户设置的还是系统推测出来的
用参数hive.mapred.local.mem(默认0)来设置local mode下mapper和reducer task jvm heap size
8q: 关键词union all的用法
a:the number and names of columns returned by each select_statement has to be the same. otherwise, a schema error is thrown.
union all两边的字段名,和字段数都必须一致,可以用as xxx来统一字段名,并且目前union all只能作为子查询。
9q:hive left outer join的问题:where 与 on 条件的区别
http://blog.csdn.net/lalaguozhe/article/details/9498947
10q:其它技巧请见:
http://my.oschina.net/leejun2005/blog/121945
11、对于 jar 包调用失败 nullpointerexception 的问题:
failed: error in metadata: java.lang.nullpointerexception
failed: execution error, return code 1 from org.apache.hadoop.hive.ql.exec.ddltask
你可能需要再 hive-site.xml 中添加 jar 的路径:
具体参考:http://abloz.com/2013/03/28/the-hive-execute-statements-times-nullpointerexception.html
1 property>
2     name>
3         hive.aux.jars.path
4     name>
5     value>
6         file:///home/june/soft/hive-0.9.0-bin/lib/hive-json-serde.jar
7     value>
8 property>
ref:http://blog.csdn.net/lalaguozhe/article/details/9081971
其它类似信息

推荐信息