【问题标题】:mrunit - Using mrunit.mapreduce.MapDriver not callling customised Record Readermrunit - 使用 mrunit.mapreduce.MapDriver 不调用自定义记录阅读器
【发布时间】:2020-02-06 10:37:11
【问题描述】:

我正在修改 Record Reader 中的 MapReduce 程序,并想为 mapper 编写一个测试用例,以调用自定义的 InputFormat 或 Record Reader。我已经修改了记录阅读器的测试用例,但记录阅读器测试用例不是 mrunit 的。

如何从Mapper调用自定义的Record Reader,因为MapDriver.newMapDriver下没有列出withInputFormat函数?

请找到我的代码快照:

@Before
public void setUp(){
MapDriver<Object, Text, Text, Text> mapDriver = MapDriver.newMapDriver(new myMapper());
}

@Test
public void testFunction1() throws IOException {
mapDriver.withInput(...).withOutput(...).runTest();
}

谢谢

【问题讨论】:

  • 好吧,MRUnit 在其 API 中有 withOutputFormat 方法。我想会有withInputFormat。这是个好问题!

标签: mapreduce mrunit


【解决方案1】:

我正在检查MRUnit API,所以。如果您想添加自定义 RecordReader,我猜您必须有自定义 InputFormat,因为必须将自定义 RecordReader 分配到自定义 InputFormat 类的 createRecordReader 方法中。

因此,MRUnit API 允许您分配自定义 InputFormat 和自定义 OutputFormat

public MapDriver<K1,V1,K2,V2> withOutputFormat(Class<? extends org.apache.hadoop.mapreduce.OutputFormat> outputFormatClass,
                                      Class<? extends org.apache.hadoop.mapreduce.InputFormat> inputFormatClass)

Configure Mapper to output with a real OutputFormat. Set InputFormat to read 
output back in for use with run* methods

Parameters:
outputFormatClass -
inputFormatClass -

Returns:
this for fluent style

基于此,您可以致电mapDriver.withOutFormat(customOutputFormat.class, customInputFormat.class)。通过这种方式,您可以使用 RecordReader 进行测试。

猜你喜欢
  • 2014-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-08
  • 2015-11-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多