【问题标题】:Implementation for CombineFileInputFormat Hadoop 0.20.205CombineFileInputFormat Hadoop 0.20.205 的实现
【发布时间】:2012-12-25 13:43:45
【问题描述】:

谁能指出我在哪里可以找到CombineFileInputFormat 的实现(组织。使用 Hadoop 0.20.205?这是使用 EMR 从非常小的日志文件(行中的文本)创建大拆分。

令人惊讶的是,Hadoop 没有专门为此目的创建的此类的默认实现,并且在谷歌上搜索它看起来并不是唯一一个对此感到困惑的人。我需要编译该类并将其捆绑在一个 jar 中以用于 hadoop-streaming,对 Java 的了解有限,这是一个挑战。

编辑: 我已经尝试过使用必要的导入的 Yetitrails 示例,但是下一个方法出现编译器错误。

【问题讨论】:

  • 您在使用雪人小径示例时遇到了哪些错误?我觉得没问题。
  • @Charles,谢谢,我得到的错误是“错误:MyKeyValueLineRecordReader 不是抽象的,并且不会覆盖 RecordReader 中的抽象方法 next(Object,Object)”

标签: java mapreduce inputformatter


【解决方案1】:

这是我为你准备的一个实现:

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileSplit;
import org.apache.hadoop.mapred.InputSplit;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.LineRecordReader;
import org.apache.hadoop.mapred.RecordReader;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapred.lib.CombineFileInputFormat;
import org.apache.hadoop.mapred.lib.CombineFileRecordReader;
import org.apache.hadoop.mapred.lib.CombineFileSplit;

@SuppressWarnings("deprecation")
public class CombinedInputFormat extends CombineFileInputFormat<LongWritable, Text> {

    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public RecordReader<LongWritable, Text> getRecordReader(InputSplit split, JobConf conf, Reporter reporter) throws IOException {

        return new CombineFileRecordReader(conf, (CombineFileSplit) split, reporter, (Class) myCombineFileRecordReader.class);
    }

    public static class myCombineFileRecordReader implements RecordReader<LongWritable, Text> {
        private final LineRecordReader linerecord;

        public myCombineFileRecordReader(CombineFileSplit split, Configuration conf, Reporter reporter, Integer index) throws IOException {
            FileSplit filesplit = new FileSplit(split.getPath(index), split.getOffset(index), split.getLength(index), split.getLocations());
            linerecord = new LineRecordReader(conf, filesplit);
        }

        @Override
        public void close() throws IOException {
            linerecord.close();

        }

        @Override
        public LongWritable createKey() {
            // TODO Auto-generated method stub
            return linerecord.createKey();
        }

        @Override
        public Text createValue() {
            // TODO Auto-generated method stub
            return linerecord.createValue();
        }

        @Override
        public long getPos() throws IOException {
            // TODO Auto-generated method stub
            return linerecord.getPos();
        }

        @Override
        public float getProgress() throws IOException {
            // TODO Auto-generated method stub
            return linerecord.getProgress();
        }

        @Override
        public boolean next(LongWritable key, Text value) throws IOException {

            // TODO Auto-generated method stub
            return linerecord.next(key, value);
        }

    }
}

在您的工作中,首先根据您希望将输入文件组合成的大小设置参数mapred.max.split.size。在您的 run() 中执行以下操作:

...
            if (argument != null) {
                conf.set("mapred.max.split.size", argument);
            } else {
                conf.set("mapred.max.split.size", "134217728"); // 128 MB
            }
...

            conf.setInputFormat(CombinedInputFormat.class);
...

【讨论】:

  • 嗨@Amar,索引来自哪里?
  • @ManikandanKannan :使用此 InputFormat 时您不必担心索引。为了使用它,只需执行conf.setInputFormat(CombinedInputFormat.class);,如上所示。但仅供参考的索引可能是在 hadoop 内部初始化记录读取器时传递的拆分数。
  • 非常感谢!在此解决方案之前需要 1 小时 40 分钟的作业现在只需要 5 分钟。此外,WholeFileRecordReader 来自 Tom White 的书。感谢您制作了这么多 cmets 来阐明其源代码 :) 干得好!
  • Brillent,我的工作使用此组合器从 30 分钟更改为 2 分钟。我的每个小文件每个大小为 5 mb,并且跨越了 4000 个映射器,以前比较过这个组合器的 71 个映射器
  • @Prometheus .. 我已经将这个 CombinedInputFormat 实现用于小文件......但没有。映射器的数量从 100 减少到 25,但是看到的但这项工作在后来的情况下需要更多的时间来执行(100 分钟到 33 分钟。)..你能告诉我你之前和之后的工作是什么,confs?这是我的问题stackoverflow.com/questions/36107504/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多