【问题标题】:Hadoop Mapper parameters explaination [duplicate]Hadoop Mapper参数说明[重复]
【发布时间】:2015-03-31 08:12:28
【问题描述】:

我是 Hadoop 的新手,对 Mapper 参数感到困惑。

以众所周知的WordCount为例:

class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> {
  private Text outputKey;
  private IntWritable outputVal;

  @Override
  public void setup(Context context) {
    outputKey = new Text();
    outputVal = new IntWritable(1);
  }

  @Override
  public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    StringTokenizer stk = new StringTokenizer(value.toString());
    while(stk.hasMoreTokens()) {
      outputKey.set(stk.nextToken());
      context.write(outputKey, outputVal);
    }
  }
}

map函数,参数是Object keyText valueContext context,我对Object key的样子感到困惑(你看,key从未在Map中使用函数)。

由于输入文件格式如下:

Deer
Beer
Bear
Beer
Deer
Deer
Bear
...

我知道 看起来像每一行 DeerBeer 等等。它们是逐行处理的。

但是 key 长什么样子呢?如何决定key应该使用哪种数据类型?

【问题讨论】:

    标签: java hadoop mapreduce cluster-computing distributed-computing


    【解决方案1】:

    这里的一切都取决于你使用的InputFormat 类。它解析输入数据源并为您提供 (Key, Value) 对。即使输入源相同,不同的输入格式实现也可以为您提供不同的流。

    这是演示方法的文章:

    https://hadoopi.wordpress.com/2013/05/31/custom-recordreader-processing-string-pattern-delimited-records/

    这里的主要驱动是RecordReader

    【讨论】:

    • 您好,链接失效了,您能帮忙看看吗?
    • 添加了不同的插图。如果您知道要搜索什么,找到它们并不难。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多