Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 运行MapReduce代码时出现FileReadyExistsException_Java_Hadoop_Mapreduce - Fatal编程技术网

Java 运行MapReduce代码时出现FileReadyExistsException

Java 运行MapReduce代码时出现FileReadyExistsException,java,hadoop,mapreduce,Java,Hadoop,Mapreduce,这个程序应该完成MapReduce的工作。第一个作业的输出必须作为第二个作业的输入 当我运行它时,会出现两个错误: 线程“main”org.apache.hadoop.mapred.FileReadyExistsException中的异常 映射部件100%运行,但减速器未运行 这是我的密码: import java.io.IOException; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.a

这个程序应该完成MapReduce的工作。第一个作业的输出必须作为第二个作业的输入

当我运行它时,会出现两个错误:

  • 线程“main”org.apache.hadoop.mapred.FileReadyExistsException中的异常
  • 映射部件100%运行,但减速器未运行
  • 这是我的密码:

    import java.io.IOException;
    
    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;
    import org.apache.hadoop.mapreduce.Mapper;
    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.Reducer;
    import org.apache.hadoop.io.LongWritable;
    
    public class MaxPubYear {
        public static class FrequencyMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
            public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
                Text word = new Text();
                String delim = ";";
                Integer year = 0;
                String tokens[] = value.toString().split(delim);
                if (tokens.length >= 4) {
                    year = TryParseInt(tokens[3].replace("\"", "").trim());
                    if (year > 0) {
                        word = new Text(year.toString());
                        context.write(word, new IntWritable(1));
                    }
                }
            }
        }
    
        public static class FrequencyReducer extends
                Reducer<Text, IntWritable, Text, IntWritable> {
            public void reduce(Text key, Iterable<IntWritable> values,
                    Context context) throws IOException, InterruptedException {
                int sum = 0;
                for (IntWritable value : values) {
                    sum += value.get();
                }
                context.write(key, new IntWritable(sum));
            }
        }
    
        public static class MaxPubYearMapper extends
                Mapper<LongWritable, Text, IntWritable, Text> {
            public void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {
                String delim = "\t";
                Text valtosend = new Text();
                String tokens[] = value.toString().split(delim);
                if (tokens.length == 2) {
                    valtosend.set(tokens[0] + ";" + tokens[1]);
                    context.write(new IntWritable(1), valtosend);
                }
    
            }
        }
    
        public static class MaxPubYearReducer extends
                Reducer<IntWritable, Text, Text, IntWritable> {
    
            public void reduce(IntWritable key, Iterable<Text> values,
                    Context context) throws IOException, InterruptedException {
                int maxiValue = Integer.MIN_VALUE;
                String maxiYear = "";
                for (Text value : values) {
                    String token[] = value.toString().split(";");
                    if (token.length == 2
                            && TryParseInt(token[1]).intValue() > maxiValue) {
                        maxiValue = TryParseInt(token[1]);
                        maxiYear = token[0];
                    }
                }
                context.write(new Text(maxiYear), new IntWritable(maxiValue));
            }
        }
    
        public static void main(String[] args) throws Exception {
            Configuration conf = new Configuration();
            Job job = new Job(conf, "Frequency");
            job.setJarByClass(MaxPubYear.class);
            job.setOutputKeyClass(Text.class);
            job.setOutputValueClass(IntWritable.class);
    
            job.setMapperClass(FrequencyMapper.class);
            job.setCombinerClass(FrequencyReducer.class);
            job.setReducerClass(FrequencyReducer.class);
    
            job.setOutputFormatClass(TextOutputFormat.class);
            job.setInputFormatClass(TextInputFormat.class);
    
            FileInputFormat.addInputPath(job, new Path(args[0]));
            FileOutputFormat.setOutputPath(job, new Path(args[1] + "_temp"));
            int exitCode = job.waitForCompletion(true) ? 0 : 1;
    
            if (exitCode == 0) {
                Job SecondJob = new Job(conf, "Maximum Publication year");
                SecondJob.setJarByClass(MaxPubYear.class);
    
                SecondJob.setOutputKeyClass(Text.class);
                SecondJob.setOutputValueClass(IntWritable.class);
    
                SecondJob.setMapOutputKeyClass(IntWritable.class);
                SecondJob.setMapOutputValueClass(Text.class);
    
                SecondJob.setMapperClass(MaxPubYearMapper.class);
                SecondJob.setReducerClass(MaxPubYearReducer.class);
    
                FileInputFormat.addInputPath(SecondJob, new Path(args[1] + "_temp"));
                FileOutputFormat.setOutputPath(SecondJob, new Path(args[1]));
                System.exit(SecondJob.waitForCompletion(true) ? 0 : 1);
    
            }
        }
    
        public static Integer TryParseInt(String trim) {
            // TODO Auto-generated method stub
            return(0);
        }
    }
    
    import java.io.IOException;
    导入org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
    导入org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
    导入org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
    导入org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
    导入org.apache.hadoop.mapreduce.Mapper;
    导入org.apache.hadoop.conf.Configuration;
    导入org.apache.hadoop.fs.Path;
    导入org.apache.hadoop.io.IntWritable;
    导入org.apache.hadoop.io.Text;
    导入org.apache.hadoop.mapreduce.Job;
    导入org.apache.hadoop.mapreduce.Reducer;
    导入org.apache.hadoop.io.LongWritable;
    公共课{
    公共静态类FrequencyMapper扩展映射器{
    公共void映射(LongWritable键、文本值、上下文上下文)引发IOException、InterruptedException{
    Text word=新文本();
    字符串delim=“;”;
    整数年=0;
    字符串标记[]=value.toString().split(delim);
    如果(tokens.length>=4){
    year=TryParseInt(标记[3]。替换(“\”,“”)。trim();
    如果(年份>0){
    word=新文本(year.toString());
    context.write(word,新的intwriteable(1));
    }
    }
    }
    }
    公共静态类FrequencyReducer扩展
    减速器{
    public void reduce(文本键、Iterable值、,
    上下文)抛出IOException、InterruptedException{
    整数和=0;
    for(可写入值:值){
    sum+=value.get();
    }
    write(key,newintwriteable(sum));
    }
    }
    公共静态类MaxPubYearMapper扩展
    制图员{
    公共void映射(可长写键、文本值、上下文)
    抛出IOException、InterruptedException{
    字符串delim=“\t”;
    Text valtosend=新文本();
    字符串标记[]=value.toString().split(delim);
    if(tokens.length==2){
    valtosend.set(令牌[0]+“;”+令牌[1]);
    write(新的intwriteable(1),valtosend);
    }
    }
    }
    公共静态类MaxPubYearReducer扩展
    减速器{
    public void reduce(可写键、可写值、,
    上下文)抛出IOException、InterruptedException{
    int maxiValue=Integer.MIN_值;
    字符串maxiYear=“”;
    用于(文本值:值){
    字符串标记[]=value.toString().split(;);
    如果(token.length==2
    &&TryParseInt(令牌[1]).intValue()>maxiValue){
    maxiValue=TryParseInt(令牌[1]);
    maxiYear=token[0];
    }
    }
    write(新文本(maxiYear),新intwriteable(maxiValue));
    }
    }
    公共静态void main(字符串[]args)引发异常{
    Configuration conf=新配置();
    作业=新作业(配置,“频率”);
    job.setJarByClass(MaxPubYear.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    job.setMapperClass(FrequencyMapper.class);
    job.setCombinerClass(FrequencyReducer.class);
    job.setReducerClass(FrequencyReducer.class);
    setOutputFormatClass(TextOutputFormat.class);
    setInputFormatClass(TextInputFormat.class);
    addInputPath(作业,新路径(args[0]);
    setOutputPath(作业,新路径(args[1]+“_temp”);
    int exitCode=job.waitForCompletion(true)?0:1;
    if(exitCode==0){
    Job SecondJob=新作业(conf,“最长出版年”);
    SecondJob.setJarByClass(MaxPubYear.class);
    SecondJob.setOutputKeyClass(Text.class);
    SecondJob.setOutputValueClass(IntWritable.class);
    setMapOutputKeyClass(IntWritable.class);
    SecondJob.setMapOutputValueClass(Text.class);
    setMapperClass(MaxPubYearMapper.class);
    SecondJob.setReducerClass(MaxPubYearReducer.class);
    addInputPath(第二个作业,新路径(args[1]+“_temp”);
    setOutputPath(第二个作业,新路径(args[1]);
    系统退出(第二个作业等待完成(真)?0:1;
    }
    }
    公共静态整数TryParseInt(字符串修剪){
    //TODO自动生成的方法存根
    返回(0);
    }
    }
    
    线程“main”中出现异常 org.apache.hadoop.mapred.filealreadyexistException

    Map reduce作业不会覆盖现有目录中的内容。MR作业的输出路径必须是不存在的目录路径。MR作业将在指定路径创建一个目录,其中包含文件

    在代码中:

    setOutputPath(作业,新路径(args[1]+“_temp”)

    确保运行MR作业时此路径不存在

    线程“main”中出现异常 org.apache.hadoop.mapred.filealreadyexistException

    Map reduce作业不会覆盖现有目录中的内容。MR作业的输出路径必须是不存在的目录路径。MR作业将在指定路径创建一个目录,其中包含文件

    在代码中:

    setOutputPath(作业,新路径(args[1]+“_temp”)

    确保运行MR作业时此路径不存在

    线程“main”中出现异常 org.apache.hadoop.mapred.filealreadyexistseceptio