MapReduce中Mapper类和Reducer类4函数解析

2019-03-28 13:34|来源: 网络

MapReduce中Mapper类和Reducer类4函数解析

Mapper类4个函数的解析
protected void setup(Mapper.Context context) throws IOException,InterruptedException //Called once at the beginning of the task
protected void cleanup(Mapper.Context context)throws IOException,InterruptedException //Called once at the end of the task.
protected void map(KEYIN key, VALUEIN value Mapper.Context context)throws IOException,InterruptedException
//Called once for each key/value pair in the input split. Most applications should override this, but the default is the identity function.
public void run(Mapper.Context context)throws IOException,InterruptedException
//Expert users can override this method for more complete control over the execution of the Mapper.
执行顺序:setup --->   map/run   ----> cleanup
同理在Reduce类中也存在4个函数
protected void setup(Mapper.Context context) throws IOException,InterruptedException //Called once at the beginning of the task
protected void cleanup(Mapper.Context context)throws IOException,InterruptedException //Called once at the end of the task.
protected void map(KEYIN key, VALUEIN value Mapper.Context context)throws IOException,InterruptedException
//This method is called once for each key. Most applications will define their reduce class by overriding this method. The default implementation is an identity function. public void run(Mapper.Context context)throws IOException,InterruptedException
//Advanced application writers can use the run(org.apache.Hadoop.mapreduce.Reducer.Context) method to control how the reduce task works
执行顺序:setup --->   map/run   ----> cleanup

相关问答

更多
  • 假设您的映射程序正在获取一个完整的句子,在该句子中您正在尝试查找频率并且正在使用Java API,则可以通过context.write(...)函数从映射程序输出两个键: 映射器的java语法: public void map(LongWritable key, Text value, Context context) 键: ; 值: c_m 键: ; 值: t_n 哪里 lineNo = same as key to the mapper ( ...
  • 这是一个想法。 你如何创建一个新的类,可以将任何类型的数据传递给reduce。 该类将包含一个toString()方法,最终将您的数据表示为一个String。 使用此字符串,使用Hadoop中的Text类可以将其用作关键字 Here is an idea. How about you create a new class that can take any type of data that you are looking to pass onto the reduce. The class will co ...
  • 您希望根据campaign_id输出。 所以Campaign_id shud是映射器代码的关键。 然后在reducer代码中,您将检查它是视图还是单击。 String actionStr = tokens[2]; String campaignStr = tokens[4]; int actionid = Integer.parseInt(actionStr.trim()); int campaignid = I ...
  • 您已经找到了一个示例,可以按照您的要求使用Java API。 但是,您正在使用流式API,它只读取标准输入并写入标准输出。 除了完成hadoop jar命令之外,mapreduce作业完成时没有回调。 但是,因为它完成了,并没有真正表明“成功”。 话虽如此,如果没有更多关于流API的工具,这是不可能的。 如果输出被写入本地终端而不是HDFS,则可能将该输出传输到另一个流作业的输入中,但不幸的是,蒸汽罐的输入和输出需要HDFS上的路径。 It is possible to do what you're ask ...
  • 不确定您在该页面上的哪个位置读取Mapper和Reducer是MapReduce2的接口,但该页面上的源代码显然使用了类。 关键字正在extends 。 import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; ... public static class TokenizerMapper extends Mapper ... public static class IntSumReducer ...
  • 实际上,您正在将旧的mapred API与新的mapreduce API混合使用。 基本上Hadoop mapreduce支持两个不兼容的API,你必须决定使用哪一个。 我可能会感到困惑,因为他们共享具有相同或相似名称的类。 您应该仔细查看您的import语句。 两种API都可以实现几乎相同的功能。 mapred尚未被弃用或删除,也没有破坏旧版应用程序。 mapreduce是相同的API,设计稍好一些。 如果你要开始一个新项目,我建议你使用新项目。 但这不是什么大不了的事。 简单的解决方法是更改org.ap ...
  • 这是解决您的问题的代码 司机 HBaseConfiguration conf = HBaseConfiguration.create(); Job job = new Job(conf,"JOB_NAME"); job.setJarByClass(yourclass.class); job.setMapperClass(yourMapper.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValue ...
  • Reduce task只是Reducer.一个实例Reducer. reduce任务的数量是可配置的。 可以通过在作业配置对象中设置属性mapred.reduce.tasks来指定它 要么 org.apache.hadoop.mapreduce.Job#setNumReduceTasks(int reducerCount); 方法可以使用。 Reduce task is simply an instance of the Reducer. The number of reduce tasks is conf ...
  • 我也在寻找同样的东西。 我确实得到了答案,即使它已经迟到了,我认为分享这个可能对某人有帮助。 从Hadoop 2.0开始,您可以在包org.apache.hadoop.mapreduce.lib.chain中找到ChainMapper和ChainReducer。 ChainMapper使用模式: ... Job job = new Job(conf, "MyJob"); Configuration map1Conf = new Configuration(false); ... ChainMapper. ...
  • 首先,您需要了解有关mapreduce框架的更多信息。 您的程序在本地模式下按预期运行,因为Mapper,reducer和Job在同一JVM上启动。 在伪分布模式或分布式模式的情况下,将为每个组件分配单独的jvms。 使用get_list放入hashMap的值对于mapper和reducer是不可见的,因为它们位于单独的jvms中 使用分布式缓存使其在群集模式下工作。 Job Main class将文件添加到分布式缓存: JobConf job = new JobConf();
    Distribute ...