MapReduce file and HBase co-input

Source: Internet
Author: User

MapReduce file and HBase co-enter the package Duogemap; import Java.io.ioexception; import Org.apache.hadoop.conf.configuration;import Org.apache.hadoop.fs.path;import Org.apache.hadoop.hbase.hbaseconfiguration;import Org.apache.hadoop.hbase.client.result;import Org.apache.hadoop.hbase.client.scan;import Org.apache.hadoop.hbase.io.immutablebyteswritable;import Org.apache.hadoop.hbase.mapreduce.tableinputformat;import Org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil; Import Org.apache.hadoop.hbase.mapreduce.tablemapper;import Org.apache.hadoop.hbase.util.bytes;import Org.apache.hadoop.io.text;import Org.apache.hadoop.mapreduce.job;import Org.apache.hadoop.mapreduce.Mapper; Import Org.apache.hadoop.mapreduce.reducer;import Org.apache.hadoop.mapreduce.lib.input.multipleinputs;import Org.apache.hadoop.mapreduce.lib.input.textinputformat;import Org.apache.hadoop.mapreduce.lib.output.fileoutputformat;import Org.apache.hadoop.mapreduce.lib.output.textoutputformat; public class Mixmr { pUblic static class Map extends Mapper<object, text, text, text> { public void map (Object key, text value, Conte XT context) throws IOException, interruptedexception {String s = value.tostring (); string[] sa = S.split (","), if (sa.length = = 2) {context.write (new text (Sa[0]), new text (sa[1]));}  } } public Static class Tablemap extends Tablemapper<text, text> {public static final byte[] CF = "C F ". GetBytes ();p ublic static final byte[] ATTR1 =" C1 ". GetBytes ();  public void Map (immutablebyteswritable row, Result value, Context context) throws IOException, interruptedexception { string key = Bytes.tostring (Row.get ()); String val = new String (Value.getvalue (CF, ATTR1));  context.write (new Text (key), new text (val));}}   public static class reduce extends Reducer <object, Text, object, text> {public void reduce (object key, Iterable<text> values, Context context) throws IOException, interruptedexception {String KS = key.tostring (); for (Text val:values) {context.write (new text (KS), Val);}  }} public static void Main (string[] args) throws Exception {path inputPath1 = new Path (args[0]); Path inputPath2 = new Path (args[1]); Path OutputPath = new Path (args[2]),  string tableName = "Test";  configuration config = Hbaseconfiguration.create (); Job Job = new Job (config, "Exampleread"); Job.setjarbyclass (Mixmr.class); Class that contains mapper scan scan = new scan (); scan.setcaching (500); 1 is the default in Scan, which would be a bad for MapReduce jobsscan.setcacheblocks (false); Don ' t set to True for MR jobsscan.addfamily (bytes.tobytes ("CF"));  tablemapreduceutil.inittablemapperjob ( TableName,//input HBase table Namescan,//Scan instance to control CF and attribute Selectiontablemap.class,//Mappert Ext.class,//Mapper output Keytext.class,//Mapper output Valuejob);   job.setreducerclass (Reduce.class); Reducer Classjob.setoutputformatclass (Textoutputformat.class);   //inPutPath1 here have no effect for HBase tablemultipleinputs.addinputpath (Job, InputPath1, Textinputformat.class, Map.class ); Multipleinputs.addinputpath (Job, InputPath2, Tableinputformat.class, Tablemap.class);  Fileoutputformat.setoutputpath (Job, OutputPath);  job.waitforcompletion (True);}}  

MapReduce file and hbase co-input

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.