无法识别此程序中的错误



Am正在为以下代码执行mapreduce。当我运行这份工作时,一切都很好。但是输出显示0 0。我怀疑这可能是由于TryprseInt()方法造成的,因为它以前是未定义的,所以我对其进行了QUICKFIXED。最初没有TryprseInt()的方法。所以我创建了一个,任何人都可以检查代码是否正确,特别是TryParseInt方法,并告诉我成功运行这个程序的任何建议。

输入看起来像:

提前感谢


    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 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, "Maximum Publication year");
            Job.setJarByClass(MaxPubYear.class);
            Job.setOutputKeyClass(Text.class);
            Job.setOutputValueClass(IntWritable.class);
            Job.setMapOutputKeyClass(IntWritable.class);
            Job.setMapOutputValueClass(Text.class);
            Job.setMapperClass(MaxPubYearMapper.class);              
            Job.setReducerClass(MaxPubYearReducer.class);
            FileInputFormat.addInputPath(Job,new Path(args[0]));
            FileOutputFormat.setOutputPath(Job,new Path(args[1]));
            System.exit(Job.waitForCompletion(true)?0:1);                
        }
public static Integer TryParseInt(String string) {
    // TODO Auto-generated method stub
    return(0);
}
    }

这些错误正是他们所说的:对于三个"无法解析为类型"的错误,您可能忘记导入正确的类。错误2只是意味着类MaxPubYear.MaxPubYearReducer中没有方法TryParseInt(String),您必须在其中创建一个方法。

相关内容

  • 没有找到相关文章

最新更新