Following the
example Map Reduce Program , that helps to scan Table on HBase. Here , I
have not used Reducer because requirement has been fulfilled in
Mapper only. This Map Reduce Program is scanning a table on Hbase and
writing it in a file on HDFS.
Here, I have used default Mapper Class. TableMapper can also be used for accessing Hbase Table.
Following is the driver class:
public class ScanTableDriver {
public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException
{
Configuration conf= new Configuration();
Job job = new Job(conf);
job.setJarByClass(ScanTableDriver.class);
job.setMapperClass(ScanTableMapper.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(NullWritable.class);
job.setInputFormatClass(TableInputFormat.class);
job.getConfiguration().set(TableInputFormat.INPUT_TABLE, "employee"); // here employee is the name of the table
FileOutputFormat.setOutputPath(job, new Path("hdfs: //namenode:address/filename"));
System.exit(job.waitForCompletion(true)?0:1);
}
}
Following is the Mapper class:
public class ScanTableMapper extends Mapper
{
Text row=new Text();
NullWritable val = NullWritable.get();
public void map(Object key, Result value,Context context)
{
row.set(value.toString());
try {
context.write(row, val);
}
catch (IOException e)
{
e.printStackTrace();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
No comments:
Post a Comment