package example2; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil; import org.apache.hadoop.hbase.mapreduce.TableOutputFormat; import org.apache.hadoop.hbase.mapreduce.TableReducer; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.util.GenericOptionsParser; //Administrator public class ImportFromFileExample { public static class ImportMapper extends Mapper<LongWritable, Text, ImmutableBytesWritable,Text >{ @Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { context.write(new ImmutableBytesWritable(Bytes.toBytes(key.get())), value); } } public static class Reducer1 extends TableReducer<ImmutableBytesWritable, Text, ImmutableBytesWritable> { private byte[] family=null; private byte[]qualifier=null; @Override protected void setup(Context context) throws IOException, InterruptedException { String column=context.getConfiguration().get("conf.column"); byte[][]colkey=KeyValue.parseColumn(Bytes.toBytes(column)); family=colkey[0]; if(colkey.length>1){ qualifier=colkey[1]; } } public void reduce(ImmutableBytesWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException { String valueCon=null; for(Text text:values){ valueCon+=text.toString(); } Put put = new Put(key.get()); put.add(family, qualifier, Bytes.toBytes(valueCon)); context.write(key, put); } } /** * @param args */ public static void main(String[] args)throws Exception { Configuration conf=HBaseConfiguration.create(); String []argArray=new GenericOptionsParser(conf, args).getRemainingArgs(); if(argArray.length!=1){ System.exit(1); } conf.set("conf.column", "family1:text"); Job job=new Job(conf,"import from hdfs to hbase"); job.setJarByClass(ImportFromFileExample.class); job.setMapperClass(ImportMapper.class); job.setOutputFormatClass(TableOutputFormat.class); job.getConfiguration().set(TableOutputFormat.OUTPUT_TABLE, "testtable"); job.setMapOutputKeyClass(ImmutableBytesWritable.class); job.setMapOutputValueClass(Text.class); job.setOutputKeyClass(ImmutableBytesWritable.class); job.setOutputValueClass(Put.class); TableMapReduceUtil.initTableReducerJob("testtable", Reducer1.class, job); FileInputFormat.addInputPaths(job, argArray[0]); System.exit(job.waitForCompletion(true) ? 0 : 1); } }
相关推荐
hadoop-2.7.2-hbase-jar.tar.gz hadoop-2.7.2-hbase-jar.tar.gz hadoop-2.7.2-hbase-jar.tar.gz
Docker(Hadoop_3.3.1+HBase_2.4.16+Zookeeper_3.7.1+Hive_3.1.3 )配置文件 搭建集群环境
该文档保护了目前比较流行的大数据平台的原理过程梳理。Hadoop,Hive,Hbase,Spark,MapReduce,Storm
包含了大量的hadoop hive hbase学习资料
Hadoop+ZooKeeper+HBase+hive(HQL)安装步骤
hadoop集群配置流程以及用到的配置文件,hadoop2.8.4、hbase2.1.0、zookeeper3.4.12
数据仓库hadoop+zookeeper+hbase集群安装方法记录,自己搭建纯手写的记录。相关软件请自行下载
搭建hadoop单机版+hbase单机版+pinpoint整合springboot
Hadoop HA高可用集群搭建(Hadoop+Zookeeper+HBase)
Centos+Hadoop+Hive+HBase
Hadoop+Zookeeper+Hbase+Hive部署
大数据 hadoop spark hbase ambari全套视频教程(购买的付费视频)
一份配置好的Hadoop和Hbase 配置文件conf,你需要修改里面的host和文件路径即可;
Google运行MapReduce来处理Bigtable中的海量数据,HBase同样利用Hadoop MapReduce来处理HBase中的海量数据;Google Bigtable利用 Chubby作为协同服务,HBase利用Zookeeper作为对应。 上图描述了Hadoop EcoSystem中的...
hadoop_hadoop-2.7.2-hbase-jar.rar hadoop_hadoop-2.7.2-hbase-jar.rar
Hadoop+Zookeeper+Hbase安装配置使用.pdf
Hadoop Hive与Hbase整合配置
从零开始hadoop+zookeeper+hbase+hive集群安装搭建,内附详细配置、测试、常见error等图文,按照文档一步一步搭建肯定能成功。(最好用有道云打开笔记)
将数据从Hadoop中向HBase载入数据,该过程大致可以分为两步: 一、将Hadoop中普通文本格式的数据转化为可被HBase识别的HFile...二、将HFile载入到HBase中,该过程实际就是将数据从一个地移动到HBase某表数据的存放地。
hadoop-2.7.5,hbase1.2.6.zookeeper.3.3.6完全分布式安装教程 hadoop-2.7.5,hbase1.2.6.zookeeper.3.3.6完全分布式安装教程 hadoop-2.7.5,hbase1.2.6.zookeeper.3.3.6完全分布式安装教程