write & read a sequence file(基于全新2.2.0API)
write & read a sequence file
write & read a sequence file
import java.io.IOException;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.SequenceFile.Writer;
import org.apache.hadoop.io.SequenceFile.Reader;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.Configuration;
public class MySequenceFile {
static private final String[] DATA = {
"this is the first",
"this is the second",
"this is the third",
"this is the forth"
};
public static void main(String[] args) throws IOException {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
Path path = new Path(args[0]);
IntWritable key = new IntWritable();
Text value = new Text();
SequenceFile.Writer writer = null;
writer = SequenceFile.createWriter(conf, Writer.file(path), Writer.keyClass(key.getClass()), Writer.valueClass(value.getClass()));
for( int i = 0; i < 1000; i++ ) {
key.set(i + 1);
value.set(DATA[i % DATA.length]);
writer.append(key,value);
}
writer.close();
SequenceFile.Reader reader = new SequenceFile.Reader(conf, Reader.file(path));
while( reader.next(key, value) ) {
String syncSeen = reader.syncSeen() ? "*" : "#";
System.err.println(key + "\t" + value + "\t" + reader.getPosition()+ "\t" + syncSeen);
}
reader.close();
}
}
write & read a sequence file(基于全新2.2.0API)的更多相关文章
- MapReduce——计算温度最大值 (基于全新2.2.0API)
MapReduce——计算温度最大值 (基于全新2.2.0API) deprecated: Job类的所有Constructors, 新的API用静态方法getInstance(conf)来去的Job ...
- write & read a MapFile(基于全新2.2.0API)
write & read a MapFile import java.io.IOException; import org.apache.hadoop.io.IntWritable; imp ...
- Configurataion Printer(基于全新2.2.0API)
Configurataion Printer import java.util.Map.Entry; import org.apache.hadoop.conf.Configuration; impo ...
- Combine small files to Sequence file
Combine small files to sequence file or avro files are a good method to feed hadoop. Small files in ...
- Predicting effects of noncoding variants with deep learning–based sequence model | 基于深度学习的序列模型预测非编码区变异的影响
Predicting effects of noncoding variants with deep learning–based sequence model PDF Interpreting no ...
- Flume性能测试报告(翻译Flume官方wiki报告)
因使用flume的时候总是会对其性能有所调研,网上找的要么就是自测的这里找到一份官方wiki的测试报告供大家参考 https://cwiki.apache.org/confluence/display ...
- Hadoop IO基于文件的数据结构详解【列式和行式数据结构的存储策略】
Charles所有关于hadoop的文章参考自hadoop权威指南第四版预览版 大家可以去safari免费阅读其英文预览版.本人也上传了PDF版本在我的资源中可以免费下载,不需要C币,点击这里下载. ...
- 基于docker快速搭建hbase集群
一.概述 HBase是一个分布式的.面向列的开源数据库,该技术来源于 Fay Chang 所撰写的Google论文"Bigtable:一个结构化数据的分布式存储系统".就像Bigt ...
- The Kernel Newbie Corner: Kernel Debugging with proc "Sequence" Files--Part 3
转载:https://www.linux.com/learn/linux-career-center/44184-the-kernel-newbie-corner-kernel-debugging-w ...
随机推荐
- ios--socket
一.打开服务器 a.在终端打开,到服务器文件路径输入命令 python chatserver.py b.当显示 Iphone Chat server started 表示成功 二.建立连接 a.设置对 ...
- 重新安装Ubuntu12.04
重新安装Ubuntu12.04 之所以我重新安装Ubuntu,因为我第一次给根目录分配的空间过小,好像是20GB吧~结果编译Android的时候,编译了3个小时候直接中止掉了.郁闷.这个也告诉我们一定 ...
- jquery 在页面中按回车 响应 事件
为了用户方便我们往往会在用户回车之后做一些事,比如登陆的时候,填完表单过后,我们习惯性的会直接按回车,当然要处理这个,jquery是很简单的,我们来看看怎么做吧. $(document).ready( ...
- "严格模式" use strict 详解
一.概述 除了正常运行模式,ECMAscript 5添加了第二种运行模式:"严格模式"(strict mode).顾名思义,这种模式使得Javascript在更严格的条件下运行. ...
- div之间有间隙以及img和div之间有间隙的原因及解决方法
原因: div 中 存在 img标签,由于img标签的 display:inline-block 属性. display:inline-block布局的元素在chrome下会出现几像素的间隙,原因是因 ...
- 51nod贪心算法入门-----任务分配问题
任务执行顺序 有N个任务需要执行,第i个任务计算时占R[i]个空间,而后会释放一部分,最后储存计算结果需要占据O[i]个空间(O[i] < R[i]). 分析: 可以抽象成,从一个整数开始,每次 ...
- object-fit: 炒鸡方便的图片居中方法
今天在项目中遇到图片居中的问题,嗯,之前也有写过解决这个问题的文章,有n种方法.不过今天要说一个新的方案:object-fit ,嗯,这个才是真的方便的方案啊. 先看预览: object-fit 只能 ...
- 【3】Bootstrap的下载和目录结构
[1]下载 去中方官网下载http://www.bootcss.com/ 如果你是做网页练习,你可以使用CDN加速服务,免去下载等痛苦,当然你使用的时候必须有连接上网络.中方的官网也提供了很多种类的C ...
- Python基于比较的排序
排序是算法学习中最基本的问题. 1.平均时间复杂度均为O(N2)的排序 1.1 插入排序 插入排序对少量元素的排序非常有效.工作机制就像打牌一样,为了将牌插入到已排好序的牌中,需要将牌与手中的牌从右向 ...
- Nginx+uWSGI+bottle 在Linux上部署
在/data/lujianxing/bottle 文件夹中创建三个文件: bottle.py bottle的源文件 a.py from bottle import Bottle, run mybott ...