程序也不报错就是执行不了,之前执行了一个其他的程序可以运行
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
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.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.Mapper.Context;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import com.hadoop.mapreduce.InvertedIndex.Combine;
import com.hadoop.mapreduce.InvertedIndex.Map;
import com.hadoop.mapreduce.InvertedIndex.Reduce;
public class Sort {
public static class Map extends Mapper<Object, Text, IntWritable, IntWritable>{
@Override
protected void map(Object key, Text value, Context context)
throws IOException, InterruptedException {
IntWritable data = new IntWritable();
String line = value.toString();
data.set(Integer.parseInt(line));
context.write(data, new IntWritable(1));
System.out.println("map");
}
}
public static class Reduce extends Reducer<IntWritable, IntWritable, IntWritable,IntWritable>{
private static IntWritable linenum = new IntWritable(1);
@Override
protected void reduce(IntWritable key, Iterable<IntWritable> values,
Context context)
throws IOException, InterruptedException {
System.out.println("reduce");
for(IntWritable val : values){
context.write(linenum, val);
linenum = new IntWritable(linenum.get()+1);
}
}
}
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
args = new String[]{"hdfs://master:9000/user/grid/input1/",
"hdfs://master:9000/user/grid/output1/"
};
Configuration conf = new Configuration();
/* conf.addResource(new Path("/home/grid/hadoop-2.2.0/etc/hadoop/core-site.xml"));
conf.addResource(new Path("/home/grid/hadoop-2.2.0/etc/hadoop/hdfs-site.xml"));*/
// String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (args.length != 2) {
System.err.println("Usage: Sort <in> <out>");
System.exit(2);
}
Job job = new Job(conf, "Sort");
job.setJarByClass(Sort.class);
job.setMapperClass(Map.class);
//job.setCombinerClass(SortReduce.class);
job.setReducerClass(Reduce.class);
job.setOutputKeyClass(IntWritable.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
|
|