reducer不工作或从未得到调用

pokxtpni  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(415)

驾驶员等级:

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
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.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class DRIVER {

public static void main(String arg[]) 
{
    try{
    Path in = new Path("aamazon.txt");
    Path out = new Path("/output");

    Configuration conf = new Configuration();

    Job job = Job.getInstance(conf);
    job.setJarByClass(DRIVER.class);
    job.setMapperClass(MAPPER.class);
    job.setReducerClass(REDUCER.class);
    job.setNumReduceTasks(0);

    FileInputFormat.addInputPath(job, in);
    FileOutputFormat.setOutputPath(job, out);

    job.waitForCompletion(true);

    System.out.println("Successful");}

    catch(Exception e){
        System.out.println(e.getMessage());
    }

}
}

Map器类:

import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class MAPPER extends Mapper<LongWritable,Text,LongWritable,Text>{

@Override
public void map(LongWritable key,Text value,Context con) 
{
    try
    {

        System.out.println(key +"\n"+ value);
        con.write(key, value);

    }

    catch(Exception e)
    {
        System.out.println(e.getMessage()); 
    }
}
}

减速器等级:

import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class REDUCER extends Reducer<LongWritable,Text,LongWritable,Text>{

@Override
public void reduce(LongWritable key,Iterable<Text> value , Context con) 
{
    System.out.println("reducer");
    try{
    for(Text t:value)
    {

        con.write(key, t);
    }
    }
    catch (Exception e)
    {
        System.out.println(e.getMessage());
    }
}
}

问题:
执行工作直到Map器
我从不打电话
如果我设置 setNumReduceTasks(0) 那么Map器就不会被调用了
有什么问题吗?

hjqgdpho

hjqgdpho1#

您已将reduce任务数设置为零。

Job job = Job.getInstance(conf);
    job.setJarByClass(DRIVER.class);
    job.setMapperClass(MAPPER.class);
    job.setReducerClass(REDUCER.class);
    job.setNumReduceTasks(0); // this should be greater than 0

即使在那之后,如果它不起作用,请检查您对下一行的“/output”路径是否有权限-

Path out = new Path("/output"); // it is in the root folder. change it to "./output"

相关问题