1

I'm new to HBase, what's the best way to retrieve results from a table, row by row? I would like to read the entire data in the table. My table has two column families say col1 and col2.

Roman Nikitchenko
  • 12,800
  • 7
  • 74
  • 110
Ananth Ravi
  • 717
  • 2
  • 7
  • 13
  • There should be facilities that would allow you to command your database to do this. What have you tried? – Hovercraft Full Of Eels May 19 '13 at 06:40
  • You will anyway be retrieving data row by row..... How many rows and what the columns are dependent on your query. – Thihara May 19 '13 at 06:41
  • I have made use of scan! But I would like to extend this as another map reduce job. ( I have a map reduce job that would read from a file and insert the data into HBase). In the Map(next) phase I would like to read row by row and process the data. Any sample code would be of great help – Ananth Ravi May 19 '13 at 06:49

4 Answers4

0

From Hbase shell, you can use scan command to list data in table, or get to retrieve a record. Reference here

nofomopls
  • 343
  • 4
  • 17
0

I think here is what you need: both through HBase shell and Java API: http://cook.coredump.me/post/19672191046/hbase-client-example

However you should understand hbase shell 'scan' is very slow (it is not cached). But it is intended only for debug purpose.

Another useful part of information for you is here: http://hbase.apache.org/book/perf.reading.html This chapter is right about reading from HBase but is is somewhat harder to understand because it assumes some level of familiarity and contains more advanced advices. I'd recommend to you this guide starting from the beginning.

Roman Nikitchenko
  • 12,800
  • 7
  • 74
  • 110
0

USe Scan api of Hbase , there you can specify start row and end row and can retrive data frm the table .

Here is an example:

http://eternaltechnology.blogspot.in/2013/05/hbase-scanner-example-scanning.html

Sourav Gulati
  • 1,359
  • 9
  • 18
0

I was looking for something like this!

Map function

public void map(ImmutableBytesWritable row, Result value, Context context) throws InterruptedException, IOException {

            String x1 = new String(value.getValue(Bytes.toBytes("ColumnFamily"), Bytes.toBytes("X1")));
            String x2 = new String(value.getValue(Bytes.toBytes("ColumnFamily"), Bytes.toBytes("X2")));


}

Driver file:

Configuration config2 = new Configuration();
            Job job2 = new Job(config1, "kmeans2");
            //Configuration for job2

            job2.setJarByClass(Converge.class);
            job2.setMapperClass(Converge.Map.class);
            job2.setReducerClass(Converge.Reduce.class);
            job2.setInputFormatClass(TableInputFormat.class);
            job2.setOutputFormatClass(NullOutputFormat.class);
            job2.setOutputKeyClass(Text.class);
            job2.setOutputValueClass(Text.class);
            job2.getConfiguration().set(TableInputFormat.INPUT_TABLE, "tablename");                   
tesract
  • 53
  • 10
Ananth Ravi
  • 717
  • 2
  • 7
  • 13