Basic HBase Java Classes and Methods – Part 5: Getting Data from a Table

Now that we have seen how to Create a table and Put data into a table, we will explore how to read data out of a table. The main skeleton code is the the same as before, but this time we will construct a Get object and pass it in to the get method of the Table object.  The get method is overloaded, so it will accept a single get request or a list of get requests.

First lets look at what the skeleton code looks like, everything except our get requests:

First we will construct a basic Get object, add three columns to it using the addColumn method, pass that to the get method of the Table object and print out the results.  Remember everything in HBase is a byte array.

Now we will create two Get objects, add them to a list and then pass them in the same way.  The result given back to us is a list which we will walk through and print the results.

Complete program is below:

The results of our program are as follows:

Next part we will look at using the Scan command to accomplish similar to what the SELECT command does in SQL.  Next Basic HBase Java Classes and Methods – Part 6: Scan a Table

This entry was posted in Data Analytics and tagged , . Bookmark the permalink.

Leave a Reply