2015-09-07 113 views
0

我想了解如何从猪脚本中集成调用mapreduce作业。如何在猪脚本中运行Mapreduce

我提到的链接 https://wiki.apache.org/pig/NativeMapReduce

但我不知道如何做到这一点,因为它会怎么理解这是我的映射或减速的代码。解释不是很清楚。

如果有人可以用一个例子来说明它,它将会非常有帮助。

由于提前, 干杯:)从pig documentation

A = LOAD 'WordcountInput.txt'; 
B = MAPREDUCE 'wordcount.jar' STORE A INTO 'inputDir' LOAD 'outputDir' 
    AS (word:chararray, count: int) `org.myorg.WordCount inputDir outputDir`; 

回答

3

实施例在上述例子中,猪从A输入数据存储到inputDir和从outputDir加载作业的输出数据。

此外,还有在HDFS一个罐子叫wordcount.jar其中有一个与主类需要设置映射器和减速器,输入和输出等

你也可以叫映射精简的护理称为org.myorg.WordCount类通过hadoop jar mymr.jar org.myorg.WordCount inputDir outputDir工作。

+0

@Fred嗨,有一个问题,我是能够执行MR工作,但大BIG查看问题在于它首先将输入复制到文件夹“inputDir”,然后才执行MapReduce作业(这里是Wordcount.jar)。因此,复制大数据会很耗时,效率也不高。你能建议一个替代不复制数据,仍然使用MapReduce代码? –

+0

我不确定STORE A INTO'inputDir'是否是强制性的。如果不是,就跳过它。如果是这样,只需将一些小型虚拟数据复制到某个位置,但是从您的mapreduce程序中的真实/大型输入中读取。 – Frederic

+0

谢谢@Fred,它解决了我的问题,尽管我无法避免存储功能。想知道如果我已经实现了我自己的猪阅读器并使用加载命令通过该加载器读取数据,那么这种技术可能不起作用,如果可以找到使用Pig Loader向Mapreduce提供数据的任何替代方式,那么它将是奖金。谢谢您的帮助。!! –

0

默认猪会预测地图/减少计划。然而,hadoop带有默认的映射器/缩减器实现;这是由猪使用 - 当地图缩小班没有确定。

Further Pig使用Hadoop中的属性及其特定属性。尝试设置,在猪脚本中的属性下方,它也应该由Pig挑选。

SET mapred.mapper.class="<fully qualified classname for mapper>" 
SET mapred.reducer.class="<fully qualified classname for reducer>" 

同样可以使用-Dmapred.mapper.class选项设置。基于Hadoop的你安装完整列表here ,性质可能是还有:

mapreduce.map.class 
mapreduce.reduce.class 

仅供参考...

hadoop.mapred已被弃用。 0.20.1之前的版本使用mapred。 之后的版本使用mapreduce。

而且猪都有自己的一组属性,可以使用命令pig -help properties

e.g. in my pig installation, below are the properties: 

The following properties are supported: 
    Logging: 
     verbose=true|false; default is false. This property is the same as -v switch 
     brief=true|false; default is false. This property is the same as -b switch 
     debug=OFF|ERROR|WARN|INFO|DEBUG; default is INFO. This property is the same as -d switch 
     aggregate.warning=true|false; default is true. If true, prints count of warnings 
      of each type rather than logging each warning. 
    Performance tuning: 
     pig.cachedbag.memusage=<mem fraction>; default is 0.2 (20% of all memory). 
      Note that this memory is shared across all large bags used by the application. 
     pig.skewedjoin.reduce.memusagea=<mem fraction>; default is 0.3 (30% of all memory). 
      Specifies the fraction of heap available for the reducer to perform the join. 
     pig.exec.nocombiner=true|false; default is false. 
      Only disable combiner as a temporary workaround for problems. 
     opt.multiquery=true|false; multiquery is on by default. 
      Only disable multiquery as a temporary workaround for problems. 
     opt.fetch=true|false; fetch is on by default. 
      Scripts containing Filter, Foreach, Limit, Stream, and Union can be dumped without MR jobs. 
     pig.tmpfilecompression=true|false; compression is off by default. 
      Determines whether output of intermediate jobs is compressed. 
     pig.tmpfilecompression.codec=lzo|gzip; default is gzip. 
      Used in conjunction with pig.tmpfilecompression. Defines compression type. 
     pig.noSplitCombination=true|false. Split combination is on by default. 
      Determines if multiple small files are combined into a single map. 
     pig.exec.mapPartAgg=true|false. Default is false. 
      Determines if partial aggregation is done within map phase, 
      before records are sent to combiner. 
     pig.exec.mapPartAgg.minReduction=<min aggregation factor>. Default is 10. 
      If the in-map partial aggregation does not reduce the output num records 
      by this factor, it gets disabled. 
    Miscellaneous: 
     exectype=mapreduce|local; default is mapreduce. This property is the same as -x switch 
     pig.additional.jars.uris=<comma seperated list of jars>. Used in place of register command. 
     udf.import.list=<comma seperated list of imports>. Used to avoid package names in UDF. 
     stop.on.failure=true|false; default is false. Set to true to terminate on the first error. 
     pig.datetime.default.tz=<UTC time offset>. e.g. +08:00. Default is the default timezone of the host. 
      Determines the timezone used to handle datetime datatype and UDFs. Additionally, any Hadoop property can be specified.