• hadoop InputFormat 类别


    FileInputFormat是所有使用文件作为数据源的InputFormat的积累。它提供两个功能:一个是定义哪些文件包含在一个作业的输入中;一个为输入文件生成分片的实现。自动将作业分块 作业分块大小与mapred-site.xml中的mapred.min.split.size和mapred.min.split.size和blocksize有关系。分片大小由如下公式来决定:
    分片大小 = max(minimumSize, min(maximumSize, blockSize))
    如果想避免文件被切分,可以采用如下两种之一,不过推荐第二种。
    1)设置minimum size 大于文件大小即可
    2)使用FileInputFormat子类并重载isSplitable方法返回false
    import org.apache.hadoop.fs.*;
    import org.apache.hadoop.mapred.TextInputFormat;
    public class NonSplittableTextInputFormat extends TextInputFormat {
      @Override
      protected boolean isSplitable(FileSystem fs, Path file) {
        return false;
      }
    }
     
    1.TextInputFormat(LongWritable,Text:字节偏移量,每行的内容)
    默认的InputFormat。键是改行文件在源文件中的偏移量,值是该行内容(不包括终止符,如换行符或者回车符)。如
    On the top of the Crumpetty Tree
    The Quangle Wangle sat,
    But his face you could not see,
    On account of his Beaver Hat.
    被表示成键值对如下:
    <0, On the top of the Crumpetty Tree>
    <33, The Quangle Wangle sat,>
    <57, But his face you could not see,>
    <89, On account of his Beaver Hat.>
     
    2.DBInputFormat:
    DBInputFormat 在读取数据时,产生的键值对是 <LongWritable,DBWritable的实例>    LongWritable仍旧是偏移量
     
    3.KeyValueInputFormat: 
    如果行中有分隔符,那么分隔符前面的作为key,后面的作为value 如果行中没有分隔符,那么整行作为key,value为空 默认分隔符为

     

    4.NLineInputFormat:
    这种格式下,split的数量就不是由文件对应block块个数决定的, 而是由设置处理多少行决定,  比如一个文件 100行, 设置NlineInputFormat 处理2行,那么会产生50个map任务, 每个map任务  仍旧一行行的处理 会调用2次map函数
     
    5.CombineTextInputFormat:将输入源目录下多个小文件 合并成一个文件(split)来交给mapreduce处理 这样只会生成一个map任务
    比如用户给的文件全都是10K那种的文件, 其内部也是用的TextInputFormat 当合并大小大于(64M)128M的时候,
    也会产生对应个数的split
  • 相关阅读:
    开源项目cmdbuild-搭建
    开源项目cmdbuild-寄语
    四 上下文切换
    withRouter的作用和一个简单应用
    封装react组件:显示五星评价
    简单使用 Easy Mock-创建线上伪数据
    react中避免内存泄漏的方法
    react中constructor和super的使用
    使用swiper设计移动端轮播图(https://www.swiper.com.cn/)
    vuex模块化练习-购物车
  • 原文地址:https://www.cnblogs.com/zhang-qc/p/5884208.html
Copyright © 2020-2023  润新知