FileInputFormat 之 NlineInputFormat
前置课程: HDFS开发环境搭建
数据
Call me by your name and I'll call you by mine.
请以你的名字呼唤我,我亦将如此。
In spite of you and me and the whole silly world going to pieces around us, I love you.
我爱你,直到世界终结。
Then she's horrible alcohol, tobacco, swearing, everything is not bad.
后来她勇敢的可怕烟酒脏话样样不差
具体代码
Mapper
public class NLineMapper extends Mapper<LongWritable, Text, Text, LongWritable> {protected void map(LongWritable key, Text value,Context context) throws IOException, InterruptedException {final String line = value.toString();final String[] split = line.split("\\s+");for (String word : split) {//在for循环体内,临时变量word的出现次数是常量1context.write(new Text(word), new LongWritable(1));}}
}
测试代码:
public static void main(String[] args) throws Exception {// 数据输入路径和输出路径args = new String[2];args[0] = "src/main/resources/nlinei/";args[1] = "src/main/resources/nlineo";Configuration cfg = new Configuration();cfg.set("mapreduce.framework.name", "local");cfg.set("fs.defaultFS", "file:///");//设置每个map可以处理多少条记录,默认是1行cfg.setInt("mapreduce.input.lineinputformat.linespermap", 2);final FileSystem filesystem = FileSystem.get(cfg);if (filesystem.exists(new Path(args[1]))) {filesystem.delete(new Path(args[1]), true);}// 定义job final Job job = Job.getInstance(cfg); // 新建一个任务job.setJarByClass(NLineDriver.class);// 设置mapjob.setMapperClass(NLineMapper.class);job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(LongWritable.class);job.setInputFormatClass(NLineInputFormat.class);job.setNumReduceTasks(0);FileInputFormat.setInputPaths(job, new Path(args[0]));FileOutputFormat.setOutputPath(job, new Path(args[1]));job.waitForCompletion(true);
}
结果:
FileInputFormat 之 NlineInputFormat相关推荐
- NLineInputFormat案例
NLineInputFormat案例 需求 1.需求说明 2.文件内容 案例分析 1. 需求 2. 输入数据 3.期望输出数据 4.Map阶段 5.Reduce阶段 6.Driver 代码实现 1.编 ...
- 大数据培训FileInputFormat实现类
FileInputFormat实现类 思考:在运行MapReduce程序时,输入的文件格式包括:基于行的日志文件. 二进制格式文件.数据库表等.那么,针对不同的数据类型,MapReduce是如 何读取 ...
- 6. FileInputFormat实现类
文章目录 FilInputFormat实现类 1. TextInputFormat 示例 2. KeyValueTextInputFormat 示例 3. NLineInputFormat 示例 4. ...
- MapReduce编程——输入类FileInputFormat(切片)及其4个实现类(kv)的用法
一个完整的MapReduce程序包括四个阶段:Map Task阶段.Shuffle阶段.Reduce Task阶段 InputFormat是一个抽象类,用于获取Input输入数据,并将其切分和打成&l ...
- FileInputFormat详解
转载:http://blog.csdn.net/hellozpc/article/details/45771933 https://my.oschina.net/leejun2005/blog/133 ...
- Hadoop的FileInputFormat解析
代码存于github:https://github.com/zuodaoyong/Hadoop 在运行MapReduce程序时,输入的文件格式有:日志文件,二进制文件,数据库表等,那么针对不同的数据类 ...
- MapReduce中FileInputFormat解析
1.概述 在map阶段,文件先被切分成split块,而后每一个split切片对应一个Mapper任务. FileInputFormat这个类先对输入文件进行逻辑上的划分,以128M为单位,将原始数据从 ...
- Hadoop中的FileInputFormat切片机制、FileInputFormat切片大小的参数配置、TextInputFormat、CombineTextInputFormat切片机制
文章目录 13.MapReduce框架原理 13.1InputFormat数据输入 13.1.4FileInputFormat切片机制 13.1.4.1切片机制 13.1.4.2案例分析 13.1.4 ...
- 8、FileInputFormat
InputFormat InputFormat FileInputFormat切片分析 FileInputFormat默认切片策略 TextInputFormat KeyValueInputForma ...
最新文章
- 分布式概念-如何访问到分布式系统中的服务
- ORACLE 执行计划2
- 对象中multipartfile 空报错_Python 为什么会有个奇怪的“...”对象?
- uint8 转换为 float
- 吴恩达机器学习总结一:初识机器学习
- 2017-7-18-每日博客-关于Linux下的通配符.doc
- Oracle学习 实战心得总结
- sklearn 细节 —— SGDClassifier、Perceptron(分类模型)
- VS配置arduino环境
- 面试官:Glide 是如何加载 GIF 动图的?
- 基于特征点检测的人脸融合技术
- react js清除浏览器缓存
- 14 POJ3363 Annoying painting tool
- ASPNET 5 和 dnx commands
- 产品基础训练 - Persona[用户画像]
- Oracle数据库学习基础
- 关于在线课程及软件开发学习--给真正希望学习的朋友
- 多线程下载王者荣耀图片
- 诺禾- tcp 网络效劳框架
- openal播放裸数据
热门文章
- 大印文化:李万博老师《总裁演说思维》课程笔记(14)
- 对抗性神经网络百度百科,生成对抗式神经网络
- android电话号码导入iphone6,将Android通讯录导入iphone的方法
- JVM性能优化(四)提高网站访问性能之Tomcat优化
- html图片白边的解决方式
- Heic是什么格式?如何在电脑里打开?
- 浅谈C语言参数可变函数的实现
- Navicat :Access violation at address ***(如004ECCF4) in module ‘navicat.exe’. Read of address ***.
- 精益与敏捷软件开发概述
- 顺丰O2O背后的商业逻辑与焦虑