【问题标题】:How to read the Hadoop Sequentil file as an input to the Hadoop job?如何读取 Hadoop Sequentil 文件作为 Hadoop 作业的输入?
【发布时间】:2012-01-11 10:53:54
【问题描述】:

我有一个顺序文件,它的键值对类型为 "org.apache.hadoop.typedbytes.TypedBytesWritable" ,我必须提供这个文件作为 Hadoop 作业的输入,并且必须只在地图中处理它。我的意思是我不必做任何需要减少的事情。

1) 我如何将 FileInputFormat 指定为 SequentialFile ?

2) map 函数的签名是什么。

3) 我将如何从 map 而不是 Reduce 获取输出?

【问题讨论】:

    标签: hadoop mapreduce sequence hadoop-streaming


    【解决方案1】:

    1) 我如何将 FileInputFormat 指定为 SequentialFile ?

    将SequenceFileAsBinaryInputFormat 设置为输入格式。这是 SequenceFileAsBinaryInputFormat 类的code。

    这里是代码

    JobConf conf = new JobConf(getConf(), getClass());
    conf.setInputFormat(SequenceFileAsBinaryInputFormat.class);
    

    2) map 函数的签名是什么。

    映射将使用 BytesWritable 作为键和值类型来调用。

    3) 我将如何从 map 而不是 Reduce 获取输出?

    将mapred.reduce.tasks 属性设置为0。地图的输出将是作业的最终输出。


    另外,看看SequenceFileAsTextInputFormat。映射将使用 Text 作为键和值类型调用。

    【讨论】:

    • 谢谢Praveen,我用过'job.setInputFormatClass(SequenceFileInputFormat.class);'会有什么不同吗?哪种格式在性能方面会更好?
    • 不确定,但认为 SequenceFileAsBinaryInputFormat 比 SequenceFileInputFormat 快。看了@代码,不过有点复杂,需要时间去理解。
    猜你喜欢
    • 1970-01-01
    • 2016-06-10
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-03
    • 1970-01-01
    相关资源
    最近更新 更多