分享

求助:在Eclipse下运行MapReduce,只运行了Map函数Reduce函数不能执行

li84897494 发表于 2015-1-26 20:58:11 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 2 14460
程序也不报错就是执行不了,之前执行了一个其他的程序可以运行



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);
        }
}


已有(2)人评论

跳转到指定楼层
nextuser 发表于 2015-1-26 21:23:53

   System.out.println("reduce");这个不会输出信息,最好去掉它


可以参考这个帖子,这个代码是完全可以运行的

新手指导,该如何在开发环境中,创建mapreduce程序

更多编程知识:
零基础学习hadoop到上手工作线路指导(编程篇)

回复

使用道具 举报

pig2 发表于 2015-1-26 23:24:36
通过什么方式判断reduce不执行的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条