/** A section of an input file. Returned by {@link
* InputFormat#getSplits(JobContext)} and passed to
* {@link InputFormat#createRecordReader(InputSplit,TaskAttemptContext)}.
*
* 文件的一部分,通过InputFormat#getSplits(JobContext)生成
* 作为参数生产RecordReader:InputFormat#createRecordReader(InputSplit,TaskAttemptContext)
* 实现了InputSplit接口
*/
@InterfaceAudience.Public
@InterfaceStability.Stable
public class FileSplit extends InputSplit implements Writable {
private Path file;
private long start;
private long length;
private String[] hosts;
private SplitLocationInfo[] hostInfos; public FileSplit() {} /** Constructs a split with host information
*
* @param file the file name。 文件名称
* @param start the position of the first byte in the file to process。第一个byte的偏移量
* @param length the number of bytes in the file to process。 split的长度
* @param hosts the list of hosts containing the block, possibly null。 split所在的主机列表
*/
public FileSplit(Path file, long start, long length, String[] hosts) {
this.file = file;
this.start = start;
this.length = length;
this.hosts = hosts;
} /** Constructs a split with host and cached-blocks information
*
* @param file the file name。 文件名称
* @param start the position of the first byte in the file to process。第一个byte的偏移量
* @param length the number of bytes in the file to process split的长度
* @param hosts the list of hosts containing the block split所在的主机列表
* @param inMemoryHosts the list of hosts containing the block in memory 在内存中保存block的机器列表
*/
public FileSplit(Path file, long start, long length, String[] hosts,
String[] inMemoryHosts) {
this(file, start, length, hosts);
hostInfos = new SplitLocationInfo[hosts.length];
for (int i = 0; i < hosts.length; i++) {
// because N will be tiny, scanning is probably faster than a HashSet
boolean inMemory = false;
for (String inMemoryHost : inMemoryHosts) {
if (inMemoryHost.equals(hosts[i])) {
inMemory = true;
break;
}
}
hostInfos[i] = new SplitLocationInfo(hosts[i], inMemory);
}
} /** The file containing this split's data. */
public Path getPath() { return file; } /** The position of the first byte in the file to process. */
public long getStart() { return start; } /** The number of bytes in the file to process. */
@Override
public long getLength() { return length; } @Override
public String toString() { return file + ":" + start + "+" + length; } ////////////////////////////////////////////
// Writable methods
//////////////////////////////////////////// @Override
public void write(DataOutput out) throws IOException {
Text.writeString(out, file.toString());
out.writeLong(start);
out.writeLong(length);
} @Override
public void readFields(DataInput in) throws IOException {
file = new Path(Text.readString(in));
start = in.readLong();
length = in.readLong();
hosts = null;
} @Override
public String[] getLocations() throws IOException {
if (this.hosts == null) {
return new String[]{};
} else {
return this.hosts;
}
} @Override
@Evolving
public SplitLocationInfo[] getLocationInfo() throws IOException {
return hostInfos;
}
}

hadoop FileSplit的更多相关文章

  1. 工作采坑札记:4. Hadoop获取InputSplit文件信息

    1. 场景 基于客户的数据处理需求,客户分发诸多小数据文件,文件每行代表一条记录信息,且每个文件以"类型_yyyyMMdd_批次号"命名.由于同一条记录可能存在于多个文件中,且处于 ...

  2. 报错org.apache.hadoop.mapreduce.lib.input.FileSplit cannot be cast to org.apache.hadoop.mapred.FileSplit

    报错 java.lang.Exception: java.lang.ClassCastException: org.apache.hadoop.mapreduce.lib.input.FileSpli ...

  3. Hadoop之倒排索引

    前言: 从IT跨度到DT,如今的数据每天都在海量的增长.面对如此巨大的数据,如何能让搜索引擎更好的工作呢?本文作为Hadoop系列的第二篇,将介绍分布式情况下搜索引擎的基础实现,即“倒排索引”. 1. ...

  4. hadoop分片分析

    上一篇分析了split的生成,现在接着来说具体的split具体内容及其相关的文件和类.以FileSplit(mapred包下org/apache/hadoop/mapreduce/lib/input/ ...

  5. hadoop输入分片计算(Map Task个数的确定)

    作业从JobClient端的submitJobInternal()方法提交作业的同时,调用InputFormat接口的getSplits()方法来创建split.默认是使用InputFormat的子类 ...

  6. Hadoop的数据输入的源码解析

    我们知道,任何一个工程项目,最重要的是三个部分:输入,中间处理,输出.今天我们来深入的了解一下我们熟知的Hadoop系统中,输入是如何输入的? 在hadoop中,输入数据都是通过对应的InputFor ...

  7. Hadoop日记Day12---MapReduce学习

    一.MapReduce简介 1.1MapReduce概述 MapReduce是一种分布式计算模型,由Google提出,主要用于搜索领域,解决海量数据的计算问题.MR由两个阶段组成:Map和Reduce ...

  8. Hadoop日记Day18---MapReduce排序分组

    本节所用到的数据下载地址为:http://pan.baidu.com/s/1bnfELmZ MapReduce的排序分组任务与要求 我们知道排序分组是MapReduce中Mapper端的第四步,其中分 ...

  9. Hadoop官方文档翻译——MapReduce Tutorial

    MapReduce Tutorial(个人指导) Purpose(目的) Prerequisites(必备条件) Overview(综述) Inputs and Outputs(输入输出) MapRe ...

随机推荐

  1. xcode 10 出现 :-1: Multiple commands produce '/Users/.../Library/Developer/Xcode/DerivedData/.../Build/Products/Dev-iphonesimulator/TLYShyNavBar/TLYShyNavBar.framework/Info.plist': 1) Target 'TLYShyNavB

    错误提示如下: :-1: Multiple commands produce '/Users/.../Library/Developer/Xcode/DerivedData/.../Build/Pro ...

  2. 创建 React 项目

    依次输入命令: npm install -g create-react-app create-react-app react16 cd my-app npm start 在浏览器中输入 local:3 ...

  3. Spring MVC框架下 从后台读取数据库并显示在前台页面【笔记自用 不推荐作为参考】

    1.书写jsp页面  people.jsp 1.设计显示格式以及内容显示 2.设计显示内容的范围 2.书写entity实体类 PeopleFormMap.java 书写传入的参数主要包括 要引用的数据 ...

  4. 【bzoj4310/hdu5030-跳蚤】后缀数组

    我真的是..调了一百年.. 傻逼的人生.. 而且这题好像可以用sam做哎!我Y出了一个奇怪的办法.. 好吧sam是不能做这题的.搞错了. 说说后缀数组好了.. 搞后缀数组 然后我们要二分一个子串,判断 ...

  5. 【洛谷 P1645】 序列 (差分约束)

    题目链接 差分约束. 设\(s[i]\)表示前\(i\)个位置有多少个数,那么对于一个限制条件\((L,R,C)\),显然有 \[s[R]-s[L-1]>=C\] 于是连一条\(L-1\)到\( ...

  6. CodeMirror编辑器文本框Textarea代码高亮插件,CodeMirror的简单实用例子

    CodeMirror是一个用于编辑器文本框textarea代码高亮javascript插件,为各种编程语言实现关键字,函数,变量等代码高亮显示,丰富的api和可扩展功能以及多个主题样式,能满足您各种项 ...

  7. 让Playground支持UIKit框架

    http://blog.diveinedu.cn/playground_uikit_ios/ 让Playground支持UIKit框架 发表于 作者 排云鹤 — 暂无评论 ↓ Xcode 6新增了Pl ...

  8. C#中文乱码转换

    string text="中文";string keyword;byte[] buffer= Encoding.UTF8.GetBytes(text);keyword=Encodi ...

  9. mybatis insert oracle 返回主键

    mybtis返回oracle主键 只需要加一点代码(红色处的代码)就可以了 <!-- 添加记录到临时表 --> <insert id="insertPlaneStateme ...

  10. KVM(八)使用 libvirt 迁移 QEMU/KVM 虚机和 Nova 虚机

    1. QEMU/KVM 迁移的概念 迁移(migration)包括系统整体的迁移和某个工作负载的迁移.系统整理迁移,是将系统上所有软件包括操作系统完全复制到另一个物理机硬件机器上.虚拟化环境中的迁移, ...