【问题标题】:Hadoop - MultipleInputsHadoop - 多输入
【发布时间】:2014-10-13 14:03:36
【问题描述】:

我正在尝试使用来自 Hadoop 的 MultipleInputs。我所有的映射器都将是 FixedLengthInputFormat。

MultipleInputs.addInputPath(job, 
                    new Path(rootDir),       
                    FixedLengthInputFormat.class, 
                    OneToManyMapper.class);

问题是每个映射器都有不同大小的固定记录宽度。

config.setInt(FixedLengthInputFormat.FIXED_RECORD_LENGTH, ??);

是否有使用 MultipleInputs 为每个映射器传递 FIXED_RECORD_LENGTH 的方法?

谢谢!

【问题讨论】:

  • 我会尝试重写一些方法来给出这种行为......如果我成功了,我会在这里发布......

标签: hadoop mapreduce apache-pig


【解决方案1】:

解决办法如下:

public class CustomFixedLengthInputFormat extends FixedLengthInputFormat{

    @Override
    public RecordReader<LongWritable, BytesWritable> createRecordReader(
            InputSplit split, TaskAttemptContext context) throws IOException,
            InterruptedException {
        //here i can control de recordLength size!
        int recordLength = ??;// getRecordLength(context.getConfiguration());
        if (recordLength <= 0) {
            throw new IOException(
                    "Fixed record length "
                            + recordLength
                            + " is invalid.  It should be set to a value greater than zero");
        }

        System.out.println("Record Length: " + recordLength);

        return new FixedLengthRecordReader(recordLength);
    }

}

【讨论】:

  • 所以您正在创建两个自定义固定长度记录阅读器并为每个路径设置它?
  • 是的。 haoop 框架负责调用“createRecordReader”。我只是设置了记录长度。
猜你喜欢
  • 1970-01-01
  • 2012-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-16
相关资源
最近更新 更多