我正在尝试实现自定义 WritableComparable,如此链接所示
当我尝试在我的映射器方法中初始化自定义可写可比较类时出现错误。我在代码中显示了我的错误。textpair 类应该在一个单独的文件中吗?
public class Myprog {
public static class MyMap extends Mapper<Object, Text, TextPair, IntWritable> {
public void map(Object key, Text value, Context context)
throws IOException, InterruptedException {
TextPair writable = new TextPair();
//ERROR in this line
//No enclosing instance of type Myprog is accessible. Must qualify
//the allocation with an enclosing instance of type Myprog
//(e.g. x.new A() where x is an instance of Myprog).
....
}
}
public static class MyReduce extends Reducer<TextPair, IntWritable, Text, Text> {
public void reduce(TextPair key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException {
}
}
public class TextPair implements WritableComparable<TextPair> {
....
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
String[] otherArgs =
new GenericOptionsParser(conf, args).getRemainingArgs();
Collections.addAll(headerList, header.split(","));
Job job = new Job(conf, "Myprog");
job.setJarByClass(Myprog.class);
job.setMapperClass(MyMap.class);
job.setReducerClass(MyReduce.class);
job.setMapOutputKeyClass(TextPair.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}