I am new to HBase. I am trying to save multiple versions in a cell in HBase but I am just getting the last saved value only. I tried the following two commands to retrieve multiple saved versions:
get 'Dummy1','abc', {COLUMN=>'backward:first', VERSIONS=>12} and scan 'Dummy1', {VERSIONS=>12}
Both returned the output as follows:
ROW COLUMN+CELL
abc column=backward:first, timestamp=1422722312845, value=rrb
1 row(s) in 0.0150 seconds The input file is as follows:
abc xyz kkk
abc qwe asd
abc anf rrb
The code for Table creation in HBase is as follows:
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class HBaseTableCreator {
public static void main(String[] args) throws Exception {
HBaseConfiguration conf = new HBaseConfiguration();
conf.set("hbase.master","localhost:60000");
HBaseAdmin hbase = new HBaseAdmin(conf);
HTableDescriptor desc = new HTableDescriptor("Dummy");
HColumnDescriptor meta = new HColumnDescriptor("backward".getBytes());
meta.setMaxVersions(Integer.MAX_VALUE);
HColumnDescriptor prefix = new HColumnDescriptor("forward".getBytes());
prefix.setMaxVersions(Integer.MAX_VALUE);
desc.addFamily(meta);
desc.addFamily(prefix);
hbase.createTable(desc);
}
}
The code to Dump the data in HBase is as follows: Main Class: import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
public class TestMain {
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException
{
// TODO Auto-generated method stub
Configuration conf=new Configuration();
//HTable hTable = new HTable(conf, args[3]);
String[] otherArgs=new GenericOptionsParser(conf,args).getRemainingArgs();
if(otherArgs.length!=2)
{
System.err.println("Usage: wordcount <in> <out>");
System.exit(2);
}
Job job=new Job(conf,"HBase dummy dump");
job.setJarByClass(TestMain.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
job.setMapperClass(TestMapper.class);
TableMapReduceUtil.initTableReducerJob("Dummy", null, job);
//job.setOutputKeyClass(NullWritable.class);
//job.setOutputValueClass(Text.class);
job.setNumReduceTasks(0);
//job.setOutputKeyClass(Text.class);
//job.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
//HFileOutputFormat.configureIncrementalLoad(job, hTable);
System.exit(job.waitForCompletion(true)?0:1);
}
}
Mapper Class:
import java.io.IOException;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Mapper;
public class TestMapper extends Mapper <LongWritable, Text, Text, Put>{
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line=value.toString();
String[] l=line.split("\\s+");
for(int i=1;i<l.length;i++)
{
Put HPut = new Put(l[0].getBytes());
HPut.add("backward".getBytes(),"first".getBytes(),l[i].getBytes());
context.write(new Text(l[0]),HPut);
}
}
}
Please tell me where I'm going wrong.