Hbase-mapreduce-hbase as an example of an output source | That Yi-Wipe smile

Source: Internet
Author: User

BlogThat Yi-Wipe smilecsdn Blog Address:http://blog.csdn.net/u012185296 itdog8 address link: http://www.itdog8.com/thread-204-1-1.html
blog post title:Hbase-mapreduce-hbase As an example of an output source | That Yi-wipe smile
Personality Signature:The furthest distance in the world is not the horizon, nor the cape, but I stand in front of you, but you do not feel my presence
Technical Direction:Flume+kafka+storm+redis/hbase+hadoop+hive+mahout+spark ... Cloud Computing Technology
Reprint statement:can be reproduced, but must be in the form of hyperlinks to indicate the original source and author information and copyright statement, thank you for your cooperation!
QQ Exchange Group:214293307 (look forward to learning with you, common progress) Reference: Http://abloz.com/hbase/book.html#mapreduce.example

Directly on the code, does not explain 、、、
Package Com.itdog8.cloud.hbase.mr.test;import Java.io.ioexception;import Org.apache.commons.logging.log;import Org.apache.commons.logging.logfactory;import Org.apache.hadoop.conf.configuration;import Org.apache.hadoop.conf.configured;import Org.apache.hadoop.fs.path;import Org.apache.hadoop.hbase.hbaseconfiguration;import Org.apache.hadoop.hbase.client.put;import Org.apache.hadoop.hbase.io.immutablebyteswritable;import Org.apache.hadoop.hbase.mapreduce.TableOutputFormat; 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; Import Org.apache.hadoop.util.tool;import Org.apache.hadoop.util.toolrunner;import com.sun.corba.se.spi.ior.writeable;/** * Testhbaseassinkmapreducemainclass * * * * * * * * * * * @author that yi smile * @date 2015-07-31 10:52:21 * */public CLass Testhbaseassinkmapreducemainclass extends configured implements Tool {private static final Log _log = Logfactory.get Log (Testhbaseassinkmapreducemainclass.class); public static class Examplesinkmapper extends Mapper<longwritable, Text, immutablebyteswritable, put> {private Str  ing rowkey = null;  Private byte[] family = null;  Private byte[] qualifier = null;  Private byte[] val = null;   Private Long ts = System.currenttimemillis ();   @Override protected void Map (longwritable key, Text value, Context context) throws IOException, Interruptedexception {       try {//logical processing//Rowkey = "";//family = null;//Qualifier = null;//val = null;    Put put put = new put (Bytes.tobytes (rowkey), TS);       Put.add (family, qualifier, Val);   Context.write (New Immutablebyteswritable (Bytes.tobytes (Rowkey)), put);   } catch (Exception e) {e.printstacktrace (); }}} @Override public int run (string[] args) throws Exception {if (args.length! = 3) {_LOG.INFO ("Usage:3 parameters needed!\nhadoop jar Hbase-build-import-1.0.0.jar <inputPath><tableName><   Columns> ");  System.exit (1);  } String InputPath = Args[0];  String tableName = args[1];   String columns = args[2];  HBase configuration Configuration conf = Hbaseconfiguration.create ();  Conf.set ("Hbase.zookeeper.quorum", "a234-198.hadoop.com,a234-197.hadoop.com,a234-196.hadoop.com");   Conf.set ("Hbase.zookeeper.property.clientPort", "2181");  Job Job Job = new Job (conf, "Import from File" + InputPath + "into table" + tableName);  Job.setjarbyclass (Testhbaseassinkmapreducemainclass.class);  Job.setmapperclass (Examplesinkmapper.class);  Job.setoutputformatclass (Tableoutputformat.class);  Job.getconfiguration (). Set (tableoutputformat.output_table, tableName);  Job.setoutputkeyclass (Immutablebyteswritable.class);  Job.setoutputvalueclass (Writeable.class);   Job.setnumreducetasks (0);   Add Input path Fileinputformat.addinputpath (Job, New Path (InputPath)); REturn job.waitforcompletion (True)? 0:1;  public static void Main (string[] args) throws IOException {configuration conf = new Configuration ();   string[] Otherargs = new Genericoptionsparser (conf, args). Getremainingargs ();  int retVal = 1;  try {retVal = Toolrunner.run (conf, new Testhbaseassinkmapreducemainclass (), Otherargs);  } catch (Exception e) {e.printstacktrace (); } system.exit (RetVal); } }


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hbase-mapreduce-hbase as an example of an output source | That Yi-Wipe smile

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.