1
我想寫一個空的mapreduce作業,其實我的意思是一個無所事事的mapreduce作業,只有一個Mapper,一個Reducer和一個主類。我想要它在hortonwoks沙箱2.1中進行測試。 這是我的代碼:編寫一個空的MapReduce作業
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
public class MainClassName {
public static class Map extends MapReduceBase
implements Mapper<IntWritable, Text, IntWritable, Text>
{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value,
OutputCollector<Text, IntWritable> output,
Reporter reporter) throws IOException
{
output.collect(word, one);
}
}
public static class Reduce extends MapReduceBase
implements Reducer<Text, IntWritable, Text, IntWritable>
{
public void reduce(Text key, Iterator<IntWritable> values,
OutputCollector<Text, IntWritable> output, Reporter reporter)
throws IOException
{
int data = 0;
}
output.collect(key, new IntWritable(data));
}
}
public static void main(String[] args) throws Exception
{
JobConf conf = new JobConf(MainClassName.class);
conf.setJobName("JobName");
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
conf.setMapperClass(Map.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
JobClient.runJob(conf);
}
}
它是正確的嗎? 但它給我一個錯誤:
描述資源路徑位置類型 類型MainClassName.Map必須實現繼承的抽象方法Mapper.map(文本,文本,OutputCollector,記者)MainClassName.java/mainempty/src目錄線14 Java問題
而且我想知道必須導入哪些java文件才能運行簡單的作業。 非常感謝。 :)
非常感謝你#btbamcostello – 2014-10-23 08:53:38