Hadoop的TextInputFormat的作用,如何自定义实现的
代码先行:【源代码】
二话不说,代码先行!
/*** Licensed to the Apache Software Foundation (ASF) under one* or more contributor license agreements. See the NOTICE file* distributed with this work for additional information* regarding copyright ownership. The ASF licenses this file* to you under the Apache License, Version 2.0 (the* "License"); you may not use this file except in compliance* with the License. You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package org.apache.hadoop.mapred;import java.io.*;import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.compress.*;import com.google.common.base.Charsets;/** * An {@link InputFormat} for plain text files. Files are broken into lines.* Either linefeed or carriage-return are used to signal end of line. Keys are* the position in the file, and values are the line of text.. */
@InterfaceAudience.Public
@InterfaceStability.Stable
public class TextInputFormat extends FileInputFormat<LongWritable, Text>implements JobConfigurable {private CompressionCodecFactory compressionCodecs = null;public void configure(JobConf conf) {compressionCodecs = new CompressionCodecFactory(conf);}protected boolean isSplitable(FileSystem fs, Path file) {final CompressionCodec codec = compressionCodecs.getCodec(file);if (null == codec) {return true;}return codec instanceof SplittableCompressionCodec;}public RecordReader<LongWritable, Text> getRecordReader(InputSplit genericSplit, JobConf job,Reporter reporter)throws IOException {reporter.setStatus(genericSplit.toString());String delimiter = job.get("textinputformat.record.delimiter");byte[] recordDelimiterBytes = null;if (null != delimiter) {recordDelimiterBytes = delimiter.getBytes(Charsets.UTF_8);}return new LineRecordReader(job, (FileSplit) genericSplit,recordDelimiterBytes);}
}
先看注释:
/** * An {@link InputFormat} for plain text files. Files are broken into lines.* Either linefeed or carriage-return are used to signal end of line. Keys are* the position in the file, and values are the line of text.. */
纯文本文件的{@link InputFormat}。文件被分成几行。换行或载波返回都用来表示行结束。键是文件
中的位置,值是文本的行。
InputFormat用于描述输入数据的格式。
TextInputFormat重写了其父类的isSplitable和RecordReader方法。
采用的编码机Charsets.UTF_8
其他的没什么说的,【主要不懂。。。】
Hadoop的TextInputFormat的作用,如何自定义实现的相关推荐
- Hadoop生态圈-Flume的组件之自定义拦截器(interceptor)
Hadoop生态圈-Flume的组件之自定义拦截器(interceptor) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本篇博客只是举例了一个自定义拦截器的方法,测试字节传输速 ...
- android 自定义xmlns,Android xmlns 的作用及其自定义实例详解
Android xmlns 的作用及其自定义实例详解 xmlns:Android="http://schemas.android.com/apk/res/android的作用是: 这个是xm ...
- 一脸懵逼学习Hadoop中的MapReduce程序中自定义分组的实现
1:首先搞好实体类对象: write 是把每个对象序列化到输出流,readFields是把输入流字节反序列化,实现WritableComparable,Java值对象的比较:一般需要重写toStrin ...
- Hadoop学习笔记—7.计数器与自定义计数器
一.Hadoop中的计数器 计数器:计数器是用来记录job的执行进度和状态的.它的作用可以理解为日志.我们通常可以在程序的某个位置插入计数器,用来记录数据或者进度的变化情况,它比日志更便利进行分析. ...
- Hadoop学习笔记—8.Combiner与自定义Combiner
一.Combiner的出现背景 1.1 回顾Map阶段五大步骤 在第四篇博文<初识MapReduce>中,我们认识了MapReduce的八大步凑,其中在Map阶段总共五个步骤,如下图所示: ...
- Android xmlns 的作用及其自定义
xmlns:android="http://schemas.android.com/apk/res/android 声明xml命名空间.xmlns意思为"xml namespace ...
- Hadoop是做什么的,hadoop集群搭建作用
目的 本文描述了如何安装.配置和管理有实际意义的Hadoop集群,其规模可从几个节点的小集群到几千个节点的超大集群. 如果你希望在单机上安装Hadoop玩玩,从这里能找到相关细节. 更多精彩内容 精彩 ...
- Hadoop学习之路(7)MapReduce自定义排序
本文测试文本: tom 20 8000 nancy 22 8000 ketty 22 9000 stone 19 10000 green 19 11000 white 39 29000 socrate ...
- android minheight的作用,Android 自定义 View 最少必要知识
1. 什么是自定义 View? 1.1 定义 在 Android 系统中,界面中所有能看到的元素都是 View.默认情况下,Android 系统为开发者提供了很多 View,比如用于展示文本信息的 T ...
最新文章
- Java中Synchronized的用法
- [WCF]配置文件中Certificate 的encodeValue怎么设置?
- java8 LocalDate 日期比较大小
- c# 取 list前100条数据
- 前端要凉?微软开源Sketch2Code,草图秒变代码
- MassTransit Get Started-
- Codeforces 835 F Roads in the Kingdom(树形dp)
- JavaScript高级程序设计:基本概念思维导图
- 数据治理——如何处理“脏数据”
- linux下设置定时器,linux定时器设置.
- 天正服务器修改,天正修改服务器地址
- 【考研政治】1. 导论和基本哲学问题
- Linux找回删除文件
- 量表:现代医学体系的“工具箱”
- 2022长三角数学建模A题
- 大数据峰会议题公开,顶级技术+实践经验先睹为快
- 冠希老师看了会流泪,分布式存储爱我你怕了吗?
- 王曦:大数据人工智能中的运筹与决策科学
- Mysql 的存储过程和存储函数
- 【python】——Python中的*和**的作用和含义