【问题标题】:hadoop textinputformat read only one line per filehadoop textinputformat 每个文件只读取一行
【发布时间】:2013-05-15 18:46:01
【问题描述】:

我为hadoop 0.20.2写了一个简单的map任务,输入数据集由44个文件组成,每个文件大约3-5MB。任何文件的每一行都具有int,int 的格式。输入格式为默认TextInputFormat,映射器的工作是将输入Text解析为整数。

任务运行后,hadoop框架统计显示map任务的输入记录数只有44条。我尝试调试发现map方法的输入记录只是每个文件的第一行.

有谁知道问题出在哪里,我在哪里可以找到解决方案?

先谢谢你了。

编辑 1

输入数据由不同的 map-reduce 任务生成,其输出格式为 TextOutputFormat<NullWritable, IntXInt>IntXInttoString() 方法应该给出 int,int 的字符串。

编辑 2

我的映射器如下所示

static class MyMapper extends MapReduceBas
  implements Mapper<LongWritable, Text, IntWritable, IntWritable> {

  public void map(LongWritable key,
                  Text value,
                  OutputCollector<IntWritable, IntWritable> output,
                  Reporter reporter) {

    String[] s = value.toString().split(",");
    IntXInt x = new IntXInt(s[0], s[1]);
    output.collect(x.firstInt(), x.secondInt());
  }
}

编辑 3

我刚刚检查过,映射器实际上只为每个文件读取 1 行,而不是整个文件作为一个 Text 值。

【问题讨论】:

  • 你看过你的输出了吗?
  • @smttsp:输出44条记录。
  • 你能提供你的减速机吗?
  • 你能给我们一个输入文件的样本头吗(hadoop fs -text part-r-00000 | head

标签: java hadoop mapreduce word-count


【解决方案1】:

InputFormat 定义了如何将文件中的数据读取到 Mapper 实例中。默认的 TextInputFormat 读取文本文件的行。它为每条记录发出的键是读取的行的字节偏移量(作为 LongWritable),值是直到终止 '\n' 字符的行的内容(作为文本对象)。如果你有多个-line 记录每个由 $ 字符分隔,您应该编写自己的 InputFormat 将文件解析为按此字符分割的记录。

【讨论】:

    【解决方案2】:

    我怀疑您的映射器将所有文本作为输入并打印输出。你能展示你的 Mapper 类 decleration 和 mapper 函数 decleration 吗?即

    static class MyMapper extends Mapper <LongWritable,Text,Text,Text>{ 
        public void map (LongWritable key, Text value, Context context) throws IOException, InterruptedException {
            //do your mapping here
    
        }
    }
    

    不知道这一行有什么不同

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-26
      • 2013-05-02
      相关资源
      最近更新 更多