`
小网客
  • 浏览: 1216499 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Hadoop之InputFormat

 
阅读更多

版本:

2.2版

描述:

InputFormat是为了读取的时候设置的输入格式,比如我们如果打算在MR的时候读文件那么我们就需要知道文件的路径以及每次mapper多少,InputFormat正是基于这个需求提出来的,也就是定义读取规则。

用途:

1.怎么读

2.从那读

首先看下InputFormat抽象类的定义

public abstract 
    List<InputSplit> getSplits(JobContext context
                               ) throws IOException, InterruptedException;
public abstract 
    RecordReader<K,V> createRecordReader(InputSplit split,
                                         TaskAttemptContext context
                                        ) throws IOException, 
                                                 InterruptedException;			     

那么getSplits中定义的就是从那读,而怎么读是在createRecordReader中定义的,我们可以看下InputSplit的定义:

public abstract long getLength() throws IOException, InterruptedException;
public abstract String[] getLocations() throws IOException, InterruptedException;

其实这个定义如果是接口那么不是很确切,这个准确的来讲是保存数据的地址以及读所用的其他资源因此用新版开始以抽象类形式出现而不是接口,具体的实现还需要根据自己的需要进行相应的添加。

那么读的抽象定义如下:

public abstract void initialize(InputSplit split, TaskAttemptContext context)
		throws IOException, InterruptedException;

public abstract boolean nextKeyValue() throws IOException,
		InterruptedException;

public abstract KEYIN getCurrentKey() throws IOException,
		InterruptedException;

public abstract VALUEIN getCurrentValue() throws IOException,
		InterruptedException;

public abstract float getProgress() throws IOException,
		InterruptedException;

public abstract void close() throws IOException;

那么这个就可以直接获取到对应的当前Value等数据信息

 

其他场景:

如果打算以mysql某表的数据作为输入源那么只需要继承此类即可(已经有实现不过需要自己重新定义DBWritable)

0
1
分享到:
评论

相关推荐

    CustomInputFormatCollection:Hadoop Mapreduce InputFormat 集合

    Hadoop 代码使用方式 ...hadoop jar hadoop-mapreduce-custom-inputformat-1.0-SNAPSHOT.jar org.apache.hadoop.mapreduce.sample.SmallFileWordCount -Dmapreduce.input.fileinputformat.split.maxsize=10

    Hadoop源码解析---MapReduce之InputFormat

    结合Hadoop源码,详细讲解了MapReduce开发中的InputFormat,很详细。

    SequenceFileKeyValueInputFormat:自定义 Hadoop InputFormat

    Apache Hive 的 InputFormat,在查询 SequenceFiles 时将返回 (Text) 键和 (Text) 值。 我需要在不拆分内容的情况下完整解析大量文本文件。 HDFS 在处理大型连续文件时提供最佳吞吐量,因此我使用 Apache Mahout 将...

    Hadoop实战中文版

    3.3 读和写 3.3.1 InputFormat 3.3.2 OutputFormat 3.4 小结第二部分 实战 第4章 编写MapReduce基础程序 4.1 获得专利数据集 4.1.1 专利引用数据 4.1.2 专利描述数据 4.2 构建MapReduce 程序的基础模板 4.3...

    mapfileinputformat:MapFiles 的 Hadoop InputFormat,它在将任何内容传递给映射器之前过滤不相关的 FileSplits

    映射文件输入格式MapFiles 的 Hadoop InputFormat,它在将任何内容传递给映射器之前过滤不相关的 FileSplits。目的假设您的文件系统中有一些带有排序键的非常大的文件,并且键已排序。 在编写 MapReduce 作业时,您...

    自定义MapReduce的InputFormat

    自定义MapReduce的InputFormat,实现提取指定开始与结束限定符的内容。

    Hadoop实战中文版.PDF

    413.2.5 Combiner:本地reduce 433.2.6 预定义mapper和Reducer类的单词计数 433.3 读和写 433.3.1 InputFormat 443.3.2 OutputFormat 493.4 小结 50第二部分 实战第4章 编写MapReduce基础程序 524.1...

    Hadoop技术内幕:深入解析MapReduce架构设计与实现原理

    MapReduce编程模型3.1 MapReduce编程模型概述3.1.1 MapReduce编程接口体系...InputFormat接口的设计与实现3.3.3 OutputFormat接口的设计与实现3.3.4 Mapper与Reducer解析3.3.5 Partitioner接口的设计与实现3.4 非...

    wikipedia-hadoop:维基百科 Inputformat 和其他有用的 Hadoop 相关的东西

    维基百科-Hadoop 维基百科输入格式和一些有用的维基百科 Hadoop 工具。用法首先,您必须将WikiInputFormat设置为您的作业 InputFormat: job . setInputFormatClass( WikiInputFormat . class); 您的 Mappers 传入 ...

    Hadoop实战(陆嘉恒)译

    Hadoop组件3.1 HDFS 文件操作3.1.1 基本文件命令3.1.2 编程读写HDFS3.2 剖析MapReduce 程序3.2.1 Hadoop数据类型3.2.2 Mapper3.2.3 Reducer3.2.4 Partitioner:重定向Mapper输出3.2.5 Combiner:本地reduce3.2.6 ...

    Hadoop实战

    433.3 读和写 433.3.1 InputFormat 443.3.2 OutputFormat 493.4 小结 50第二部分 实战第4章 编写MapReduce基础程序 524.1 获得专利数据集 524.1.1 专利引用数据 534.1.2 专利描述数据 544.2 构建MapReduce程序的基础...

    hadoop-lzo-lib

    编译环境:centos 6.4 64bit、maven 3.3.9、jdk1.7.0_79、lzo-2.09;...解决:hive报错:Cannot create an instance of InputFormat class org.apache.hadoop ....... as specified in mapredwork!

    自定义inputFormat&&outputFormat1

    自定义inputFormat&&outputFormat1

    couchbase-inputformat:将 Couchbase 集成到 Hadoop 等云项目的工具

    ##Couchbase InputFormat 提供什么? 在与 Couchbase Sqoop 连接器搏斗时,发现了一些错误,使其无法与 CDH3 版本正常工作。 从 Couchbase 中提取键/值的实际 InputFormat 存在于 Sqoop 连接器的基于代码中,但对 ...

    Spark RDD详解

    它可以通过YARN或Spark的Standalone在Hadoop集群中运行,并且可以处理HDFS、Hbase、Cassandra、Hive和任何Hadoop InputFormat中的数据。它旨在执行批处理(类似于MapReduce)和提供新的工作特性,例如流计算,SparkSQL...

    FocusBigData:【大数据成神之路学习路径+面经+简历】

    FocusBigData :elephant:Hadoop分布存储框架 Hadoop篇 HDFS篇 ...MapReduce之InputFormat数据输入 MapReduce之OutputFormat数据输出 MapReduce之Shuffle机制 MapReduce之MapJoin和ReduceJoin MapReduce之

    Hadoop-CombineFileInputFormat:hadoop CombineFileInputFormat的示例实现

    合并文件InputFormat演示我的演示项目。安装下载项目并运行命令: mvn package 编译的jar是target/CombineFileDemo-0.0.1-SNAPSHOT.jar 。用法hadoop jar CombineFileDemo-0.0.1-SNAPSHOT.jar TestMain &lt;src&gt; 执照...

    探索HadoopOutputFormat

    上个月InfoQ展示了怎样在第一个步骤中,使用InputFormat类来更好地对接收输入文件进行控制。而在本文中,我们将同大家一起探讨怎样自定义最后一个步骤——即怎样写入输出文件。OutputFormat将Map/Reduce作业的输出...

    ExcelRecordReaderMapReduce:可以读取Excel文件的MapReduce InputFormat

    ExcelRecordReaderMapReducehadoop ... 不支持Zip文件执行任务为&gt; hadoop jar ExcelRecordReaderMapReduce-0.0.1-SNAPSHOT-jar-with-dependencies.jar出来作业完成后,您可以检查HDFS中输出目录的内容。 hadoop fs

Global site tag (gtag.js) - Google Analytics