hadoop 、hive 的一些使用经验。

1、queue的设置

  hadoop2.0支持了queue,在hadoop程序里面进行queue的配置: 

  job.getConfiguration().set("mapred.job.queue.name", "your-queue-name");

2、reduce key-value中间的分隔符。

  首先得保证outputformart是Textoutputformat,默认的分割符是'\t',用以下语句在程序中进行配置:

  job.getConfiguration().set("mapred.textoutputformat.separator", "some-separator");

3、hive输出本地文件的分割符

  在0.10.0之前的hive版本儿输出到本地文件列之间的分隔符是看起来是“^A”,java读取的时候是"\\x01"

4、MR读取input输入不同地址,运用不同的mapper class

  org.apache.hadoop.mapreduce.lib.input.MultipleInputs.addInputPath(job, new Path(otherArgs[0]),TextInputFormat.class);

  org.apache.hadoop.mapreduce.lib.input.MultipleInputs.addInputPath(job, new Path(otherArgs[1]),TextInputFormat.class );

  用2.0以上版本儿的maven依赖。

5、hive的sort和order by在reduce步骤的区别

  sort 会执行多个reduce数据,输出多个reduce结果文件,每个文件之间进行排序

  order by只执行一个reduce,结果会排序。

  所以如果需要总体排序的话尽量不要用sort,用order by

6、不知道是所有的数据库只有hive有这个问题,hive的left、full join的时候,后面如果跟上where条件,就会自动识别成普通的join。

  官方解释:

will join a on b, producing a list of a.val and b.val. The WHERE clause, however, can also reference other columns of a and b that are in the output of the join, and then filter them out. However, whenever a row from the JOIN has found a key for a and no key for b, all of the columns of b will be NULL, including the ds column. This is to say, you will filter out all rows of join output for which there was no valid b.key, and thus you have outsmarted your LEFT OUTER requirement. In other words, the LEFT OUTER part of the join is irrelevant if you reference any column of b in the WHERE clause.

7、在hive中,concat_ws和cast XXX as string 联合起来比较好用。number_format会出现一些比较恶心的问题,比如如果是空值null的话会报错。
8、在hive中,case when XXX is null then '' end是不行的,必须得是 case when XXX is nul then '' else XXX end才能返回正确的结果。记住必须有end。
9、在hive中,如果用streaming的方式做map的时候,用的map的文件其中如果有问题的话,hive不会报错出来,会提示成功但是没有返回结果。所以在用streaming之前一定要先检查好map 、reduce的程序,得在python程序中加上try catche,然后错误日志需要在yarn的log里面查询:yarn -logs applicationId=XXXXX
10、在hive中,如果语句中用streaming的方式添加了第三方的程序来执行reduce,如果是python的话,在using里面要加上python XXX.py否则reduce会报错,为什么这样还不是很清楚,如果第三方程序用在map上面的话,就不需要加python。原因应该是这样的:如果是用第三方程序的话,如果不直接写明是map或者reduce的话,那么就不用写明是什么提供的,如果写明了是map还是reduce的话,就需要写明是什么提供的。
11、在hive中,如果source表里面的数据比较碎,导致map数量太多,则需要set hive.input.format=org.apache.hadoop.hive.ql.io.CombineHiveInputFormat;set mapred.max.split.size=100000000;set mapred.min.split.size.per.node=100000000;set mapred.min.split.size.per.rack=100000000;这个数值是根据经验设置的,一般是文件较多的话,数值会较小。
12、hive-streaming报错代码为20001,可能的原因有三种情况:1、脚本本身没有main函数,2、脚本的编码没有转换到unix的格式,3、using ‘python XXX.py’。测试python 脚本的map的时候,可以用本地文件 cat XXX | python XXX.py
13、在向新表插入数据时报错:
Currently the writer can only accept BytesRefArrayWritable。这个错误是hive的一个bug,在一个rcfile表select insert into 到另一个rcfile的表的时候会报错。解决方法就是,将目标表改为text的存储方式。另外网上也介绍了一个方法:ALTER TABLE table_name SET SERDEPROPERTIES('serialization.null.format'='-1'),经测试不好用。hive版本儿时:0.11

 

 

posted @ 2014-04-02 15:46  fbiswt  阅读(903)  评论(0编辑  收藏  举报