0

我是 hadoop 新手,我正在关注 hadop 权威学习指南。我正在使用 MRunit 进行单元测试,但是在为减少任务进行测试时,我遇到了编译错误。

下面是我的reduce java文件:MaxTemperatureReducer.java

package org.priya.mapred.mapred;

import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
//import org.apache.hadoop.mapred.MRBench.Reduce;
import org.apache.hadoop.mapreduce.Reducer;

public class MaxTemperatureReducer extends Reducer<Text, IntWritable , Text, IntWritable> {

    public void reduce(Text key,Iterator<IntWritable> values, Context context) throws InterruptedException ,IOException
    {
        int maxValue = Integer.MIN_VALUE;
        while(values.hasNext())
        {
            IntWritable value =values.next();
            if(maxValue >= value.get())
            {
                maxValue= value.get();
            }
        }

        context.write(key, new IntWritable(maxValue));

    }

}

下面是我的 Junit 测试文件:MaxTemperatureReducerTest.java

package org.priya.mapred.mapred;

import static org.junit.Assert.*;
import java.util.ArrayList;
import org.junit.Test;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
//import org.apache.hadoop.mrunit.ReduceDriver;
import org.apache.hadoop.mrunit.ReduceDriver;
//import org.apache.hadoop.mrunit.mapreduce.MapReduceDriver;

public class MaxTemperatureReducerTest {

    @Test
    public void reducerTestValid()
    {   
        ArrayList<IntWritable> listOfValues = new ArrayList<IntWritable>();
        listOfValues.add(new IntWritable(20));
        listOfValues.add(new IntWritable(30));
        listOfValues.add(new IntWritable(40));
        listOfValues.add(new IntWritable(60));
        new ReduceDriver<Text ,IntWritable , Text,  IntWritable>()
                        .withReducer(new MaxTemperatureReducer())
                        .withInput(new Text("1950"),listOfValues )
                        .withOutput(new Text("1950"), new IntWritable(60));



    }

}

当我使用驱动程序类的withReducer() 方法将reduceclass 的实例,即new MaxTemperatureReducer() 传递给我的reducerdriver 时。我得到低于编译错误。

The method withReducer(Reducer<Text,IntWritable,Text,IntWritable>) in the type ReduceDriver<Text,IntWritable,Text,IntWritable> is not applicable for the arguments (MaxTemperatureReducer)

请帮帮我,因为我可以看到 MaxTemperatureMapper 类扩展了 Reducer 类,我无法理解为什么 withReducer() 方法不接受 MaxTemperatureReducer 实例。

谢谢, 普里亚兰詹

4

1 回答 1

1

你的减速器必须实现:http ://hadoop.apache.org/docs/current2/api/org/apache/hadoop/mapred/Reducer.html

您正在扩展:org.apache.hadoop.mapreduce.Reducer。

于 2014-02-07T21:11:50.827 回答