Database Reference
In-Depth Information
Accessing HBase
In the previous chapter, we saw how to create a table and simple data operations
using the HBase shell. HBase can be accessed using a variety of clients, such as REST
clients, Thrift client, object mapper framework—Kundera, and so on. HBase clients
are discussed in detail in Chapter 6 , HBase Clients . HBase also offers advanced Java-
based APIs for playing with tables and column families. (HBase shell is a wrapper
around this Java API.) This API also supports metadata management, for example,
data compression for column family, region split, and so on. In addition to schema
deinition, the API also provides an interface for a table scan with various functions
such as limiting the number of columns returned or limiting the number of versions
of each cell to be stored. For data manipulation, the Hbase API supports create,
read, update, and delete operations on individual rows. This API comes with many
advanced features, which will be discussed throughout this topic.
In most parts of the topic, all of the sample code or full examples
will be using Java-based HBase API only. There are many other
options layered on top of the Java API to access HBase, that is,
ORM—Kundera, REST gateway, Phoenix, and so on. These clients
are covered in Chapter 6 , HBase Clients , in detail.
Establishing a connection
Before performing any kind of operation in an HBase table using Java-based HBase
API, a connection needs to be established with the help of the HConnection class.
This class is managed by the shared HConnectionManager class. Once the connection
is established, it returns an HTable instance located in the org.apache.hadoop.
hbase.client package. This class provides the user with all the functionality
needed to store and retrieve data:
HTableInterface usersTable = new HTable("Costumers");
From the preceding code, we can verify that the usage of the HConnection and
HConnectionManager classes is not mandatory as the HTable constructor reads the
default coniguration to create a connection. If there is a need to use or deine the
connection explicitly, the following code can be used with a custom coniguration:
Configuration newConfig = new Configuration(defaultConfig);
HConnection connection =
HConnectionManager.createConnection(newConfig);
HTableInterface table = connection.getTable("Costumers");
 
Search WWH ::




Custom Search