Community Blog How to Use HBase Client to Access Alibaba Cloud NoSQL Table Store

How to Use HBase Client to Access Alibaba Cloud NoSQL Table Store

Alibaba Cloud NoSQL Table Store is a scalable and fully managed NoSQL database service, based on automatic data partitioning and load balancing technologies.



The Alibaba Cloud NoSQL Table Store is a scalable and fully managed NoSQL database service, based on automatic data partitioning and load balancing technologies. Built on SSD technology, this cloud NoSQL database service enables you to store large quantities of structured and semi-structured data with real-time access. Furthermore, it facilitates strong consistency and single-digit millisecond latency.

Using HBase Client to Access Alibaba Cloud NoSQL Table Store has the following advantages:

● Authenticates each request to prevent unauthorized data access to NoSQL servers.
● Easily scales reserved resources based on real-time application hosting needs.
● Provides seamless scaling of applications hosted on the cloud.
● Automated failure detection and quick failure recovery.

We will go into the details of how you can use HBase client to access Alibaba Cloud Table Store. However, we will start by briefly introducing related terms such as Apache HBase, Table Store, and HBase Client. This information will help you understand the steps in a more effective manner.

Apache HBase

Apache HBase is a Hadoop database that belongs to the Hadoop ecosystem. Since the release of Google’s publications on ‘The Google File System, MapReduce: Simplified Data Processing on Large Clusters and Bigtable: A Distributed Storage System for Structured Data', four years ago, the open source circle has been taking these as inspiration to design the three open-source systems. The best one being the Hadoop ecology, which corresponds to Hadoop, HDFS and HBase respectively. The current Hadoop ecology is a benchmark in the industry owing to its large-scale application and honing for more than a decade. So established is the current Hadoop ecology that it is "forcing" NoSQL's originator Google Bigtable to support HBase wrapper and provide the Bigtable HBase client.

Table Store

Unlike HBase which uses Java, Table Store is a NoSQL database independently developed by Alibaba Cloud. It uses C++ for development, just like Bigtable.

Since Table Store is a NoSQL database similar to HBase, it plays a significant role in its functioning. In most scenarios, Table Store may even outperform HBase. However, Table Store has certain advanced features not available in HBase.

HBase Client

HBase client, provided by HBase is for users to access HBase conveniently. It supports reading, writing, scanning, batch operation, table management as well as other features.

Now that we have explained the related elements, let us move forward towards understanding the various aspects of using HBase client to access Alibaba Cloud NoSQL Table Store.

The Challenge

Since a long time, Hadoop Ecology has been a widely applied solution amongst various organizations as the only open-source big data solution. At present, most companies with self-built data processing systems use Hadoop ecosystems, such as HBase. Earlier, when migrating data to Alibaba Cloud's NoSQL Table Store, the users required to rewrite the client code to use Table Store. Though this approach results in higher performance and is user-friendly, it is highly time-consuming in the early stages. Table Store introduced the Table Store HBase client last year to address this problem.


If you were previously using HBase Client to access HBase, you only require changing the dependency on HBase Client to Table Store HBase client in the project now. Furthermore, you also need to modify the hbase.client.connection.impl value in the hbase-site.xml to com.alicloud.tablestore.hbase.TablestoreConnection without any other changes to the code. Let us look at an example and the steps for effective usage of HBase client. This would make understanding the concept much easier.

Code Location

We will adopt the current program as an example using the HBase API to access the Table Store service. The complete program is accessible at Github's Alibaba Cloud Table Store HBase client for Java project, which is at src/test/java/samples/HelloWorld.java.

Steps for Using HBase Client to Access Alibaba Cloud NoSQL Table Store

Step 1. Configure Project Dependencies

The first step in this would be to configure project dependencies.
You can configure the Maven dependency as follows:


Step 2. Configure files

Then you would need to add the following configuration items in hbase-site.xml:


Step 3. Connect to Table Store

Next, connect to Table Store service by creating a Table Store connection object by executing the following code:

        Configuration config = HBaseConfiguration.create();

        // Create a Table Store connection
        Connection connection = ConnectionFactory.createConnection(config);

        // Admin is in charge of creating, managing and deleting connections.
        Admin admin = connection.getAdmin();

Step 4. Create a Table

Once you have connected to a Table Store service, specify the table name to create a table. For this, use default values for MaxVersion and TimeToLive.

        // Create an HTableDescriptor with only one column family
        HTableDescriptor descriptor = new HTableDescriptor(TableName.valueOf(TABLE_NAME));

        // Create a column family. Use default values for MaxVersion and TimeToLive. The default value of MaxVersion is 1 and the default value of TimeToLive is Integer.INF_MAX. 
        descriptor.addFamily(new HColumnDescriptor(COLUMN_FAMILY_NAME));

        // Create a table using the Admin createTable interface
        System.out.println("Create table " + descriptor.getNameAsString());

Step 5. Write Data

You would now need to write a row of data to Table Store. The steps of writing data are:

// Create a Table Store table for reading, writing, updating and deleting operations on a single table
        Table table = connection.getTable(TableName.valueOf(TABLE_NAME));

        // Create a Put object with the primary key as row_1
        System.out.println("Write one row to the table");
        Put put = new Put(ROW_KEY);

     // Add a column. Table Store only supports single column families. The column family name is configured in hbase-site.xml. If it is not configured, the default value of "f" applies. Therefore, you can leave the COLUMN_FAMILY_NAME null when writing data. 

 // Execute the table put operation. Use the HBase API to write the row of data to Table Store. 

Step 6. Read Data

Further, you need to read data in a specified row by running the code below.

  // Create a Get object and read the row with a primary key of ROW_KEY
        Result getResult = table.get(new Get(ROW_KEY));
        Result result = table.get(get);

  // Prints the results
        String value = Bytes.toString(getResult.getValue(COLUMN_FAMILY_NAME, COLUMN_NAME));
        System.out.println("Get one row by row key");
        System.out.printf("\t%s = %s\n", Bytes.toString(ROW_KEY), value);

Step 7. Scan Data

Then, read data by range by executing the following:

    Scan data in all the rows in the table.
    System.out.println("Scan for all rows:");
    Scan scan = new Scan();

    ResultScanner scanner = table.getScanner(scan);

    // Print the result in cycles
    for (Result row : scanner) {
        byte[] valueBytes = row.getValue(COLUMN_FAMILY_NAME, COLUMN_NAME);
        System.out.println('\t' + Bytes.toString(valueBytes));

Step 8. Delete a Table

Next, use Admin API to delete a table.

        print("Delete the table");


At present, some users use Table Store. Constant optimization takes place for Table Store HBase client based on user feedback with an aim to elevate its performance close to the level of the native Table Store.

Although Table Store HBase client can also access Table Store, users are recommended to access Table Store with the Table Store SDK for better performance, a wider range of features and a better price. Therefore, in OLTP (OnLine Transaction Processing) scenarios, Table Store is better suited for web applications, for example, social networks, games, media sharing, IoT, and log monitoring. You can access the official Alibaba Cloud website for Table Store for more information.

0 0 0
Share on

Alibaba Clouder

2,605 posts | 747 followers

You may also like