MapReduce生成HFile文件、加载HFile到HBase
1、程序代码
public class TransformHFile extends Configured implements Tool{ public static final String COLUMN_FAMILY = "info"; public static final String[] COLUMNS = new String[]{"rowkey","name","deptname","leader","joindate","sal","exp","deptno"}; //7499 ALLEN SALESMAN 7698 1981-2-20 1600.00 300.00 30 static class TransFormMapper extends Mapper<LongWritable, Text, ImmutableBytesWritable, Put>{ ImmutableBytesWritable outkey = new ImmutableBytesWritable(); @Override protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, ImmutableBytesWritable, Put>.Context context) throws IOException, InterruptedException { String line = value.toString(); //TODO validate data // .... String[] fields = new String[8]; StringTokenizer token = new StringTokenizer(line); int i = 0; while (token.hasMoreTokens()){ fields[i++] = token.nextToken(); } outkey.set(Bytes.toBytes(fields[0])); Put put = new Put(Bytes.toBytes(fields[0])); for(int index=1;index<8 ;index++){ if(StringUtils.isNotEmpty(fields[index])) put.add(Bytes.toBytes(COLUMN_FAMILY),Bytes.toBytes(COLUMNS[index]), Bytes.toBytes(fields[index])); } context.write(outkey,put); } } public int run(String[] args) throws Exception { Job job = Job.getInstance(this.getConf(), this.getClass().getSimpleName()); job.setJarByClass(this.getClass()); job.setMapperClass(TransFormMapper.class); job.setMapOutputKeyClass(ImmutableBytesWritable.class); job.setMapOutputValueClass(Put.class); FileInputFormat.addInputPath(job, new Path(args[1])); FileOutputFormat.setOutputPath(job, new Path(args[2])); HFileOutputFormat2.configureIncrementalLoad(job, new HTable(getConf(),args[0])); int exitcode = job.waitForCompletion(true) ? 0 : 1; return exitcode; } public static void main(String[] args) throws Exception{ /*args = new String[]{ "emp2", "hdfs://hadoop-ehp.hyman.com:8020/user/ehp/hbase/importtsv/emp/input2", "hdfs://hadoop-ehp.hyman.com:8020/user/ehp/hbase/importtsv/emp/mapredHFile" };*/ Configuration conf = HBaseConfiguration.create(); int exitcode = ToolRunner.run(// conf, // new TransformHFile(), // args// ); System.exit(exitcode); } }
2.打包运行
HADOOP_CLASSPATH=`${HBASE_HOME}/bin/hbase mapredcp`:${HBASE_HOME}/conf \ yarn jar $HADOOP_HOME/jars/mapred.jar \ com.hyman.ehp.mapred.hbase.TransformHFile \ emp \ /user/ehp/hbase/importtsv/emp/input \ /user/ehp/hbase/importtsv/emp/mapredHFile \
3.加载HFile到HBase中
HADOOP_CLASSPATH=`${HBASE_HOME}/bin/hbase mapredcp`:${HBASE_HOME}/conf \ ${HBASE_HOME}/bin/hbase org.apache.hadoop.hbase.mapreduce.LoadIncrementalHFiles \ /user/ehp/hbase/importtsv/emp/mapredHFile \ emp
相关推荐
MapReduce生成HFile入库到HBase 可能需要的jar包,一共有3个 可以直接放在每台机器的${HADOOP_HOME}/lib下 hadoopHadoop 1.1.2 + hbase 0.94.6.1
HBase MapReduce完整实例.rar
mapreduce方式入库hbase hive hdfs,速度很快,里面详细讲述了代码的编写过程,值得下载
Eclipse工程 HBase MapReduce完整实例 可远程执行 包含HBase增删改查 执行Test可看到效果
基于Hadoop的mapreduce 在hbase上的使用,基于Hadoop的mapreduce 在hbase上的使用
对Hadoop中的HDFS、MapReduce、Hbase系列知识的介绍。如果想初略了解Hadoop 可下载观看
基于hadoop的简单网络爬虫,HBase MapReduce
HBase批量加载 使用 MapReduce 作业从文本文件加载 HBase
HBase的 HBase MapReduce投影
NULL 博文链接:https://jsh0401.iteye.com/blog/2096103
该案例中主要使用MapReduce作为处理组件进行数据处理,实现的案例有如通过javaapi实现hbase数据写入hdfs、hbase表数据复制到另一个表中等操作 对应(《HBase分布式存储系统应用》胡鑫喆 张志刚著)教材中案例
HDFS+MapReduce+Hive+HBase十分钟快速入门.pdf
mapreduce生成RCFile的jar包
#资源达人分享计划#
Hadoop-0.20.0-HDFS+MapReduce+Hive+HBase十分钟快速入门
google mapreduce bigtable hbase 三篇最著名的中文论文
3、运行MapReduce程序生成HFile hadoop -jar BigGeoDataHbaseLoader.jar class路径 -Dhbase.zookeeper.quorum=zookeeper集群地址 输入空间数据tsv文件路径 输出HFile路径 空间数据表名 4、将HFile添加到HBase表中 ...
hadoop1.1.2操作例子 包括hbase hive mapreduce相应的jar包
利用hadoop的mapreduce把oracle/mysql中的数据导入到hbase和hdfs中的两个java程序
包中含有hadoop-eclipse-plugin-2.6.0.jar ,hadoop.dll,winutils.exe 三个文件,是windows 运行mapreduce 的配置文件。hadoop2.8.1亲测可用