Created
September 16, 2014 07:24
-
-
Save rishav-rohit/1224ae3df5f609083619 to your computer and use it in GitHub Desktop.
HBase multi table input union example driver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.rishav.hbase.union; | |
import java.util.ArrayList; | |
import java.util.List; | |
import org.apache.hadoop.conf.Configuration; | |
import org.apache.hadoop.conf.Configured; | |
import org.apache.hadoop.hbase.client.Scan; | |
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil; | |
import org.apache.hadoop.hbase.util.Bytes; | |
import org.apache.hadoop.io.IntWritable; | |
import org.apache.hadoop.io.Text; | |
import org.apache.hadoop.mapreduce.Job; | |
import org.apache.hadoop.util.Tool; | |
public class UnionJob extends Configured implements Tool { | |
@Override | |
public int run(String[] arg0) throws Exception { | |
List<Scan> scans = new ArrayList<Scan>(); | |
Scan scan1 = new Scan(); | |
scan1.setAttribute("scan.attributes.table.name", Bytes.toBytes("storeSales")); | |
System.out.println(scan1.getAttribute("scan.attributes.table.name")); | |
scans.add(scan1); | |
Scan scan2 = new Scan(); | |
scan2.setAttribute("scan.attributes.table.name", Bytes.toBytes("onlineSales")); | |
System.out.println(scan2.getAttribute("scan.attributes.table.name")); | |
scans.add(scan2); | |
Configuration conf = new Configuration(); | |
Job job = new Job(conf); | |
job.setJarByClass(UnionJob.class); | |
TableMapReduceUtil.initTableMapperJob( | |
scans, | |
UnionMapper.class, | |
Text.class, | |
IntWritable.class, | |
job); | |
TableMapReduceUtil.initTableReducerJob( | |
"totalSales", | |
UnionReducer.class, | |
job); | |
job.waitForCompletion(true); | |
return 0; | |
} | |
public static void main(String[] args) throws Exception { | |
UnionJob runJob = new UnionJob(); | |
runJob.run(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment