| Forum Home > Bigdata Learnings( Hadoop, HBase,Hive and other bigdata technologies) > HBase:Map Reduce on HBase : Scanning HBase Table using Map Reduce | ||
|---|---|---|
|
Site Owner Posts: 83 |
Following the example Map Reduce Program , that helps to scan Table on HBase. Here , I have not used Reducer because requirement has been fullfilled in Mapper only. Thsi 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(); }
}
| |
| ||