简体   繁体   English

还原未运行,但作业已成功完成

[英]Reduce doesn't run but job is successfully completed

Firstly, I am a newbie at Hadoop MapReduce. 首先,我是Hadoop MapReduce的新手。 My reducer does not run but shows that the job is successfully completed. 我的减速器未运行,但显示作业已成功完成。 Below is my console output : 下面是我的控制台输出:

    • INFO mapreduce.Job: Running job: job_1418240815217_0015 INFO mapreduce.Job:正在运行的作业:job_1418240815217_0015
    • INFO mapreduce.Job: Job job_1418240815217_0015 running in uber mode : false INFO mapreduce.Job:以超级模式运行的Job job_1418240815217_0015:false
    • INFO mapreduce.Job: map 0% reduce 0% INFO mapreduce.Job:地图0%减少0%
    • INFO mapreduce.Job: map 100% reduce 0% INFO mapreduce.Job:地图100%减少0%
    • INFO mapreduce.Job: Job job_1418240815217_0015 completed successfully INFO mapreduce.Job:作业job_1418240815217_0015成功完成
    • INFO mapreduce.Job: Counters: 30 INFO mapreduce.Job:计数器:30

The main class is : 主要课程是:

public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    @SuppressWarnings("deprecation")
    Job job = new Job(conf,"NPhase2");

    job.setJarByClass(NPhase2.class);

    job.setMapOutputKeyClass(IntWritable.class);
    job.setMapOutputValueClass(NPhase2Value.class);
    job.setOutputKeyClass(NullWritable.class);
    job.setOutputValueClass(Text.class);        

    job.setMapperClass(MapClass.class);        
    job.setReducerClass(Reduce.class);

    int numberOfPartition = 0;  
    List<String> other_args = new ArrayList<String>();

    for(int i = 0; i < args.length; ++i) 
    {
        try {
            if ("-m".equals(args[i])) {
                //conf.setNumMapTasks(Integer.parseInt(args[++i]));
                ++i;
            } else if ("-r".equals(args[i])) {
                job.setNumReduceTasks(Integer.parseInt(args[++i]));
            } else if ("-k".equals(args[i])) {
                int knn = Integer.parseInt(args[++i]);
                conf.setInt("knn", knn);
                System.out.println(knn);
            } else {
                other_args.add(args[i]);
            }
            job.setNumReduceTasks(numberOfPartition * numberOfPartition);
            //conf.setNumReduceTasks(1);
        } catch (NumberFormatException except) {
            System.out.println("ERROR: Integer expected instead of " + args[i]);
        } catch (ArrayIndexOutOfBoundsException except) {
            System.out.println("ERROR: Required parameter missing from " + args[i-1]);
        }
    } 

    // Make sure there are exactly 2 parameters left.
    if (other_args.size() != 2) {
        System.out.println("ERROR: Wrong number of parameters: " +
            other_args.size() + " instead of 2.");
    }

    FileInputFormat.setInputPaths(job, other_args.get(0));
    FileOutputFormat.setOutputPath(job, new Path(other_args.get(1)));

    System.exit(job.waitForCompletion(true) ? 0 : 1);
}

My mapper is : 我的映射器是:

public static class MapClass extends Mapper { 公共静态类MapClass扩展了Mapper {

    public void map(LongWritable key, Text value, Context context)  throws IOException, InterruptedException 
    {
        String line = value.toString();
        String[] parts = line.split("\\s+");
        // key format <rid1>
        IntWritable mapKey = new IntWritable(Integer.valueOf(parts[0]));
        // value format <rid2, dist>
        NPhase2Value np2v = new NPhase2Value(Integer.valueOf(parts[1]), Float.valueOf(parts[2]));
        context.write(mapKey, np2v);
    }
}

My reducer class is : 我的减速器类是:

public static class Reduce extends Reducer<IntWritable, NPhase2Value, NullWritable, Text> 
    {
        int numberOfPartition;  
        int knn;

        class Record 
    {
        public int id2;
        public float dist;

        Record(int id2, float dist) 
        {
            this.id2 = id2;
            this.dist = dist;
        }

        public String toString() 
        {
            return Integer.toString(id2) + " " + Float.toString(dist);  
        } 
    }

    class RecordComparator implements Comparator<Record> 
    {
        public int compare(Record o1, Record o2) 
        {
            int ret = 0;
            float dist = o1.dist - o2.dist;

            if (Math.abs(dist) < 1E-6)
                ret = o1.id2 - o2.id2;
            else if (dist > 0)
                ret = 1;
            else 
                ret = -1;

            return -ret;
        }   
    }

    public void setup(Context context) 
    {
        Configuration conf = new Configuration();
        conf = context.getConfiguration();
        numberOfPartition = conf.getInt("numberOfPartition", 2);    
        knn = conf.getInt("knn", 3);
    }   

    public void reduce(IntWritable key, Iterator<NPhase2Value> values, Context context) throws IOException, InterruptedException 
    {
        //initialize the pq
        RecordComparator rc = new RecordComparator();
        PriorityQueue<Record> pq = new PriorityQueue<Record>(knn + 1, rc);

        // For each record we have a reduce task
        // value format <rid1, rid2, dist>
        while (values.hasNext()) 
        {
            NPhase2Value np2v = values.next();

            int id2 = np2v.getFirst().get();
            float dist = np2v.getSecond().get();
            Record record = new Record(id2, dist);
            pq.add(record);
            if (pq.size() > knn)
                pq.poll();
        }

        while(pq.size() > 0) 
        {
            context.write(NullWritable.get(), new Text(key.toString() + " " + pq.poll().toString()));
            //break; // only ouput the first record
        }

    } // reduce
}

This is my helper class : 这是我的助手课:

public class NPhase2Value implements WritableComparable { 公共类NPhase2Value实现WritableComparable {

private IntWritable first;
private FloatWritable second;

public NPhase2Value() {
    set(new IntWritable(), new FloatWritable());
}

public NPhase2Value(int first, float second) {
    set(new IntWritable(first), new FloatWritable(second));
}

public void set(IntWritable first, FloatWritable second) {
    this.first = first;
    this.second = second;   
}

public IntWritable getFirst() {
    return first;
}

public FloatWritable getSecond() {
    return second;
}

@Override
public void write(DataOutput out) throws IOException {
    first.write(out);
    second.write(out);
}

@Override
public void readFields(DataInput in) throws IOException {
    first.readFields(in);
    second.readFields(in);
}

@Override
public boolean equals(Object o) {
    if (o instanceof NPhase2Value) {
        NPhase2Value np2v = (NPhase2Value) o;
        return first.equals(np2v.first) && second.equals(np2v.second);
    }
    return false;
}

@Override
public String toString() {
    return first.toString() + " " + second.toString();
}

@Override
public int compareTo(NPhase2Value np2v) {
    return 1;
}

}

The command line command I use is : 我使用的命令行命令是:

hadoop jar knn.jar NPhase2 -m 1 -r 3 -k 4 phase1out phase2out

I am trying hard to figure out the error but still not able to come up with solution. 我正在努力找出错误,但仍然无法提出解决方案。 Please help me in this regards as I am running on a tight schedule. 由于时间紧迫,请在这方面帮助我。

Because you have set the number of reducer task as 0. See this: 因为您已将reducer任务的数量设置为0。请参见:

 int numberOfPartition = 0;  
 //.......
 job.setNumReduceTasks(numberOfPartition * numberOfPartition);

I dont see you have resetted numberOfPartition anywhere in your code. 我看不到您已在代码中的任何地方重置了numberOfPartition I thins you should set it where you are parsing -r option or remove call to setNumReduceTasks method as above completely as you are setting it already while parsing -r option. 我认为您应该在解析-r选项的地方设置它,或者完全像上面那样完全删除对setNumReduceTasks方法的调用,因为您在解析-r选项时已经设置了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM