write & read a MapFile(基于全新2.2.0API)
2024-08-30 16:09:37
write & read a MapFile
import java.io.IOException; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.Text; import org.apache.hadoop.io.MapFile; import org.apache.hadoop.io.MapFile.Writer; import org.apache.hadoop.io.MapFile.Reader; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; public class MyMapFile { 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); String uri = args[0]; IntWritable key = new IntWritable(); Text val = new Text(); MapFile.Writer writer = new MapFile.Writer(conf, new Path(uri), Writer.keyClass(key.getClass()), Writer.valueClass(val.getClass())); for( int i = 0; i < 10; i++ ) { key.set( i + 1 ); val.set(DATA[ i % DATA.length ]); writer.append(key, val); } writer.close(); MapFile.Reader reader = new MapFile.Reader(new Path(uri), conf); while( reader.next(key, val) ){ System.out.println( key + "\t" + val ); } reader.close(); } }
最新文章
- 21-React的学习
- sed 命令使用
- MySQL Error Handling in Stored Procedures
- EF深入系列--细节
- Counting Sequences_线段树***
- Xamarin Android布局文件没有智能提示
- Linux下Openssl的安装全过程
- java 不寻常的问题 No bean named &;#39;sessionFactory&;#39; is defined 和 initialize a collection of role
- 详解CockroachDB事务处理系统
- php工作两年了。。。
- TF-IDF_MapReduceJava代码实现思路
- 使用Keepalived配置主从热备实现Nginx高可用(HA)
- Java 容器 &; 泛型:五、HashMap 和 TreeMap的自白
- idea护眼设置
- OGG实现两台Oracle数据库的同步
- PyQt5初级教程(一)
- 向jupyter notebook加入Anaconda3中已添加的虚拟环境kernel
- 02 如何创建线程 线程并发与synchornized
- Eclipse安装php插件phpeclipse(转)
- 2-功能1:基于用户认证组件和Ajax实现登录验证(图片验证码)