运行一个Hadoop Job所需要指定的属性
生活随笔
收集整理的這篇文章主要介紹了
运行一个Hadoop Job所需要指定的属性
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1、設(shè)置job的基礎(chǔ)屬性
Job job = new Job(); job.setJarByClass(***.class); job.setJobName(“job name”); job.setNumReduce(2);
2、設(shè)置Map與Reudce的類
job.setMappgerClass(*.class); job.setReduceClass(*.class);
3、設(shè)置Job的輸入輸出格式
void setInputFormatClass(Class<? extends InputFormat> cls)void setOutputFormatClass(Class<? extends OutputFormat> cls)前者默認(rèn)是TextInputFormat,后者是FileOutputFormat。
4、設(shè)置Job的輸入輸出路徑
當(dāng)輸入輸出是文件時(shí),需要指定路徑。
5、設(shè)置map與reduce的輸出鍵值類型
主要有以下4個(gè)類
void setOutputKeyClass(Class<?> theClass)void setOutputValueClass(Class<?> theClass)void setMapOutputKeyClass(Class<?> theClass)void setMapOutputValueClass(Class<?> theClass)
(1)前面2個(gè)方法設(shè)置整個(gè)job的輸出,即reduce的輸出。默認(rèn)情況下,map的輸出類型與reduce一致,若二者不一致,則需要通過(guò)后面2個(gè)方法來(lái)指定map的輸出類型。
(2)關(guān)于輸入類型的說(shuō)明:reduce的輸入類型由output的輸出類型決定。map的輸入類型由輸入格式?jīng)Q定,如輸入格式是FileInputFormat,則輸入KV類型為L(zhǎng)ongWriterable與Text。
6、運(yùn)行程序
job.waitForCompletion()。
見(jiàn)以下示例:
package org.jediael.hadoopdemo.maxtemperature;import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;public class MaxTemperature {public static void main(String[] args) throws Exception {if (args.length != 2) {System.err.println("Usage: MaxTemperature <input path> <output path>");System.exit(-1);}//1、設(shè)置job的基礎(chǔ)屬性Job job = new Job();job.setJarByClass(MaxTemperature.class);job.setJobName("Max temperature");//2、設(shè)置Map與Reudce的類job.setMapperClass(MaxTemperatureMapper.class);job.setReducerClass(MaxTemperatureReducer.class);//4、設(shè)置map與reduce的輸出鍵值類型job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);//5、設(shè)置輸入輸出路徑FileInputFormat.addInputPath(job, new Path(args[0]));FileOutputFormat.setOutputPath(job, new Path(args[1]));//6、運(yùn)行程序System.exit(job.waitForCompletion(true) ? 0 : 1);} }
總結(jié)
以上是生活随笔為你收集整理的运行一个Hadoop Job所需要指定的属性的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Gora官方文档之二:Gora对Map-
- 下一篇: 读取Webpage表中的内容