hadoop输入格式(InputFormat)

  InputFormat接口里包括两个方法:getSplits()和createRecordReader(),这两个方法分别用来定义输入分片和读取分片的方法。

 1 public abstract class InputFormat<K, V> {
 2
 3   /**
 4    * Logically split the set of input files for the job.
 5    *
 6    * <p>Each {@link InputSplit} is then assigned to an individual {@link Mapper}
 7    * for processing.</p>
 8    *
 9    * <p><i>Note</i>: The split is a <i>logical</i> split of the inputs and the
10    * input files are not physically split into chunks. For e.g. a split could
11    * be <i>&lt;input-file-path, start, offset&gt;</i> tuple. The InputFormat
12    * also creates the {@link RecordReader} to read the {@link InputSplit}.
13    *
14    * @param context job configuration.
15    * @return an array of {@link InputSplit}s for the job.
16    */
17   public abstract
18     List<InputSplit> getSplits(JobContext context
19                                ) throws IOException, InterruptedException;
20
21   /**
22    * Create a record reader for a given split. The framework will call
23    * {@link RecordReader#initialize(InputSplit, TaskAttemptContext)} before
24    * the split is used.
25    * @param split the split to be read
26    * @param context the information about the task
27    * @return a new record reader
28    * @throws IOException
29    * @throws InterruptedException
30    */
31   public abstract
32     RecordReader<K,V> createRecordReader(InputSplit split,
33                                          TaskAttemptContext context
34                                         ) throws IOException,
35                                                  InterruptedException;
36
37 }

撒发生

时间: 2024-12-26 08:07:55

hadoop输入格式(InputFormat)的相关文章

hadoop自定义输入格式

一个任务的开始阶段是由InputFormat来决定的! 1.在MapReduce框架中,InputFormat扮演的角色:– 将输入数据切分成逻辑的分片(Split),一个分片将被分配给一个单独的Mapper– 提供RecordReader的对象,该对象会从分片中读出<Key-Value>对供Mapper处理 1.1InputFormat对Mapper的影响:– 决定了Mapper的数量– 决定了Mapper的map函数接收的Key和Value 1.2InputFormat: InputFor

MapReduce输入格式

文件是 MapReduce 任务数据的初始存储地.正常情况下,输入文件一般是存储在 HDFS 里面.这些文件的格式可以是任意的:我们可以使用基于行的日志文件, 也可以使用二进制格式,多行输入记录或者其它一些格式.这些文件一般会很大,达到数十GB,甚至更大.那么 MapReduce 是如何读取这些数据的呢?下面我们来学习 InputFormat 接口 1.InputFormat接口 InputFormat接口决定了输入文件如何被 Hadoop分块(split up)与接受.InputFormat

有五个学生,每个学生有3门课(语文、数学、英语)的成绩, * 写一个程序接收从键盘输入学生的信息,输入格式为:name,30,30,30(姓名,三门课成绩)

/* * 3. 有五个学生,每个学生有3门课(语文.数学.英语)的成绩, * 写一个程序接收从键盘输入学生的信息,输入格式为:name,30,30,30(姓名,三门课成绩), * 然后把输入的学生信息按总分从高到低的顺序写入到一个名称"stu.txt"文件中. * 要求:stu.txt文件的格式要比较直观,打开这个文件,就可以很清楚的看到学生的信息 * */ import java.io.*; import java.util.*; public class Test3 { publi

commoncrawl 源码库是用于 Hadoop 的自定义 InputFormat 配送实现

commoncrawl 源码库是用于 Hadoop 的自定义 InputFormat 配送实现. Common Crawl 提供一个示例程序 BasicArcFileReaderSample.java (位于 org.commoncrawl.samples) 用来配置 InputFormat. commoncrawl / commoncrawl Watch414 Fork86 CommonCrawl Project Repository — More... http://www.commoncr

C# 各种输入格式验证#各种输入格式验证

/// <summary> /// 各种输入格式验证 /// </summary> public class ValidateUtil { private static Regex RegNumber = new Regex("^[0-9]+$"); private static Regex RegNumberSign = new Regex("^[+-]?[0-9]+$"); private static Regex RegDecimal

三道习题(1、将单词表中由相同字母组成的单词归成一类,每类单词按照单词的首字母排序,并按 #每类中第一个单词字典序由大到小排列输出各个类别。 #输入格式:按字典序由小到大输入若干个单词,每个单词占一行,以end结束输入。)

#coding=gbk ''' 1.将单词表中由相同字母组成的单词归成一类,每类单词按照单词的首字母排序,并按 #每类中第一个单词字典序由大到小排列输出各个类别. #输入格式:按字典序由小到大输入若干个单词,每个单词占一行,以end结束输入. #cinema #iceman #maps #spam #aboard #abroad #end #输出格式:一类单词一行,类别间单词以空格隔开. #aboard abroad #cinema iceman #maps spam ''' result=[]

[python]特殊输入格式(输入中包含空格逗号等)

特殊输入格式 输入中包含空格 a,b=map(int,input().split()) a,b,c=map(int,input().split()) 输入中包含 '/' a,b=map(int,input().split('/')) 输入中包含',' a,b=map(int,input().split(',')) 原文地址:https://www.cnblogs.com/xzzheng/p/10316428.html

C++学习 | 通过正则表达式保证输入格式的正确性

--仅记录个人学习过程-- 如果题目中提出了"读入特定输入格式的数据,如果不符合要求则抛出异常.输出错误提示.结束程序"的要求,使用C++的普通输入流无法解决.我使用的方法是逐行读入.结合正则表达式. 题目要求: 从input.txt文件中读入以下内容 首先输入一个正整数n,表示接下来输入的数据总行数. 输入n行数据,每行形如"C 0 1 3"或"L 2 3 5 3"或"S 3 6 4 1"(字符'C'后跟三个整数,或字符'L

[Hadoop] - 自定义Mapreduce InputFormat&amp;OutputFormat

在MR程序的开发过程中,经常会遇到输入数据不是HDFS或者数据输出目的地不是HDFS的,MapReduce的设计已经考虑到这种情况,它为我们提供了两个组建,只需要我们自定义适合的InputFormat和OutputFormat,就可以完成这个需求,这里简单的介绍一个从MongoDB中读数据,并写出数据到MongoDB中的一种情况,只是一个Demo,所以数据随便找的一个. 一.自定义InputFormat MapReduce中Map阶段的数据输入是由InputFormat决定的,我们查看org.a