本文整理汇总了Java中org.apache.hadoop.mrunit.mapreduce.MapReduceDriver.setReducer方法的典型用法代码示例。如果您正苦于以下问题:Java MapReduceDriver.setReducer方法的具体用法?Java MapReduceDriver.setReducer怎么用?Java MapReduceDriver.setReducer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.mrunit.mapreduce.MapReduceDriver
的用法示例。
在下文中一共展示了MapReduceDriver.setReducer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWithMRUnit
import org.apache.hadoop.mrunit.mapreduce.MapReduceDriver; //导入方法依赖的package包/类
@Test
public void testWithMRUnit() throws IOException {
MapReduceDriver<LongWritable, Text, Text, IntWritable, Text, IntWritable> driver =
new MapReduceDriver<LongWritable, Text, Text, IntWritable, Text, IntWritable>();
driver.setMapper(new StartsWithCountMapper());
driver.setReducer(new StartsWithCountReducer());
LongWritable k = new LongWritable();
driver.withInput(k, new Text("This is a line number one"));
driver.withInput(k, new Text("This is another line"));
driver.withOutput(new Text("T"), new IntWritable(2));
driver.withOutput(new Text("a"), new IntWritable(2));
driver.withOutput(new Text("i"), new IntWritable(2));
driver.withOutput(new Text("l"), new IntWritable(2));
driver.withOutput(new Text("n"), new IntWritable(1));
driver.withOutput(new Text("o"), new IntWritable(1));
driver.runTest();
}
示例2: verifyMapReduce
import org.apache.hadoop.mrunit.mapreduce.MapReduceDriver; //导入方法依赖的package包/类
public static void verifyMapReduce(SmartMapper mapper, SmartReducer reducer, Object key, Object input)
throws Exception
{
MapDriver mapDriver = new MapDriver();
mapDriver.setMapper(mapper);
MapReduceDriver mapReduceDriver = new MapReduceDriver();
mapReduceDriver.setMapper(mapper);
Object writableKey = WritableUtils.createWritable(key, mapper.getKeyInType());
Object writableValue = WritableUtils.createWritable(input, mapper.getValueInType());
mapDriver.withInput(writableKey, writableValue);
List results = mapDriver.run();
Collections.sort(results, PairComparer.INSTANCE);
mapReduceDriver = new MapReduceDriver<LongWritable, Text, Text, LongWritable, Text, LongWritable>();
writableKey = WritableUtils.createWritable(key, mapper.getKeyInType());
writableValue = WritableUtils.createWritable(input, mapper.getValueInType());
mapReduceDriver.withInput(writableKey, writableValue);
mapReduceDriver.setMapper(mapper);
mapReduceDriver.setReducer(reducer);
List finalResults = mapReduceDriver.run();
String text = String.format("[%s]\n\n -> maps via %s to -> \n\n%s\n\n -> reduces via %s to -> \n\n%s", input,
mapper.getClass().getSimpleName(), ArrayUtils.toString(results, Echo.INSTANCE),
reducer.getClass().getSimpleName(), ArrayUtils.toString(finalResults, Echo.INSTANCE));
Approvals.verify(text);
}