2012-10-28 72 views
3

我正在Hadoop MapReduce框架中编写Java实现程序。我正在写一个名为CombinePatternReduce.class的类。为了在Eclipse中调试减速机,我写了main()功能如下:Hadoop MapReduce Java实现中的减速器

@SuppressWarnings("unchecked") 
public static void main(String[] args) throws IOException, InterruptedException{ 
    Text key = new Text("key2:::key1:::_ performs better than _"); 
    IntWritable count5 = new IntWritable(5); 
    IntWritable count3 = new IntWritable(3); 
    IntWritable count8 = new IntWritable(8); 
    List<IntWritable> values = new ArrayList<IntWritable>(); 
    values.add(count5); 
    values.add(count3); 
    values.add(count8); 
    CombinePatternReduce reducer = new CombinePatternReduce(); 
    Context dcontext = new DebugTools.DebugReducerContext<Text, IntWritable, KeyPairWritableComparable, WrapperDoubleOrPatternWithWeightWritable>(reducer, key, count3); // here is the problem 
    reducer.reduce(key, values, dcontext);  
} 

DebugTools.DebugReducerContext是我写尽调试过程中容易执行的一类,它是如下:

public static class DebugReducerContext<KIN, VIN, KOUT, VOUT> extends Reducer<KIN, VIN, KOUT, VOUT>.Context { 
    DebugTools dtools = new DebugTools(); 
    DataOutput out = dtools.new DebugDataOutputStream(System.out); 

    public DebugReducerContext(Reducer<KIN, VIN, KOUT, VOUT> reducer, Class<KIN> keyClass, Class<VIN> valueClass) throws IOException, InterruptedException{ 
     reducer.super(new Configuration(), new TaskAttemptID(), new DebugRawKeyValueIterator(), null, null, 
       null, null, null, null, keyClass, valueClass); 
    } 

    @Override 
    public void write(Object key, Object value) throws IOException, InterruptedException { 
     writeKeyValue(key, value, out); 
    } 

    @Override 
    public void setStatus(String status) { 
     System.err.println(status); 
    } 
} 

的问题是在代码,即main()第一部分。当我写

Context dcontext = new DebugTools.DebugReducerContext<Text, IntWritable, KeyPairWritableComparable, WrapperDoubleOrPatternWithWeightWritable>(reducer, key, count3); 

有是

The constructor DebugTools.DebugReducerContext<Text,IntWritable,KeyPairWritableComparable,WrapperDoubleOrPatternWithWeightWritable>(CombinePatternReduce, Text, IntWritable) is undefined. 

当我写

Context dcontext = new DebugTools.DebugReducerContext<Text, IntWritable, KeyPairWritableComparable, WrapperDoubleOrPatternWithWeightWritable>(reducer, key, values); 

有一个错误,

The constructor DebugTools.DebugReducerContext<Text,IntWritable,KeyPairWritableComparable,WrapperDoubleOrPatternWithWeightWritable>(CombinePatternReduce, Text, List<IntWritable>) is undefined. 

由于Reducer.Context的文件是错误的

public Reducer.Context(Configuration conf, 
         TaskAttemptID taskid, 
         RawKeyValueIterator input, 
         Counter inputKeyCounter, 
         Counter inputValueCounter, 
         RecordWriter<KEYOUT,VALUEOUT> output, 
         OutputCommitter committer, 
         StatusReporter reporter, 
         RawComparator<KEYIN> comparator, 
         Class<KEYIN> keyClass, 
         Class<VALUEIN> valueClass) 
       throws IOException, 
         InterruptedException 

我需要在Class<KEYIN> keyClassClass<VALUEIN> valueClass通过。那么如何编写main()函数(特别是带有错误的句子)来调试reducer类呢?

+3

如果你想单元测试你的逻辑,使用MRUnit。如果您有输入,请使用localrunner。没有必要构建自己的上下文。 –

回答

0

这是非常清楚的类的构造函数需要3个参数。 Reducer的一个实例,键的类和值的类。

,而不是实际传递键和值。您需要提供链接到类别

Context dcontext = new DebugTools.DebugReducerContext<Text, IntWritable, KeyPairWritableComparable, WrapperDoubleOrPatternWithWeightWritable>(reducer, Text.class, IntWritable.class); 

本质上这是重申上下文应该能够处理以减少的值的类型。