我是hadoop新手,我正在遵循Hadop学习指南。我用mrunit进行单元测试,但是在为reduce任务进行测试时,我遇到了编译错误。
下面是我的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测试file: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));
}
}
当我使用driver类的withreducer()方法将reduceclass的示例new maxtemperaturereducer()传递给我的reducedriver时。我发现编译错误了。
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示例。
谢谢,普里亚兰詹
1条答案
按热度按时间dfuffjeb1#
减速机必须实现:http://hadoop.apache.org/docs/current2/api/org/apache/hadoop/mapred/reducer.html
您正在扩展:org.apache.hadoop.mapreduce.reducer。