Access LindormTable by using a non-Java HBase SDK

更新时间:
复制 MD 格式

The Lindorm wide-column engine supports access through non-Java HBase APIs, such as C++, Python, and Go. This topic describes how to install the SDK and perform access operations.

Background information

The Lindorm wide table engine supports access from non-Java languages (such as C++, Python, and Go) through Thrift.

The wide table engine of Lindorm uses the HBase Thrift2 interface definition, so you need to download the HBase Thrift2 definition file to generate language-specific interfaces. Compared with the HBase Thrift1 definition, the HBase Thrift2 interface definition in Lindorm is clearer and provides an API calling experience similar to that of Java. The HBase Thrift2 definition file currently provides more comprehensive features and is easier to use than the HBase Thrift1 definition file.

Prerequisites

  • You have downloaded the Thrift installation package.

  • You have downloaded the HBase Thrift2 definition file.

  • You have obtained the endpoint for Access by using a non-Java ApsaraDB for HBase API. For more information, see View endpoints. On the Database connection page of your Lindorm instance, select the LindormTable tab, expand the ApsaraDB for HBase-compatible endpoints section, and then copy the HTTP endpoint in the Access by using a non-Java ApsaraDB for HBase API section for the VPC or public network. The port is 9190.

Access LindormTable (Python example)

For instructions on how to use the Thrift installation package, see the Apache Thrift official documentation. The following steps describe how to use Thrift to access LindormTable:

  1. Use the HBase Thrift2 definition file to generate the interface files for your target language. Run the following command:

    thrift --gen <language> hbase.thrift
    Note

    The language parameter specifies the generator flag for your target language, such as py for Python, php, or cpp. For a complete list of supported languages and their corresponding generator flags, see the Apache Thrift official documentation.

    For example, to generate the Python interface files, set the language parameter to py and run the following command:

    thrift --gen py hbase.thrift
  2. Create a client to access Lindorm wide table engine.

    The Thrift server in Lindorm uses HTTP for its transport layer. Therefore, you must use the ThttpClient transport implementation when creating a client. If Access Control List (ACL) is enabled for your instance, you must add two custom headers to the ThttpClient object to pass the username and password. This step is not required if ACL is disabled. Each language-specific implementation of ThttpClient provides a function to set custom headers. The following Python example shows how to create a client and access LindormTable.

    # -*- coding: utf-8  -*-
    # The following two modules are generated by running the 'pip install thrift' command.
    from thrift.protocol import TBinaryProtocol
    from thrift.transport import THttpClient
    # The following two modules are generated by running the 'thrift --gen py hbase.thrift' command.
    from hbase import THBaseService
    from hbase.ttypes import TColumnValue, TColumn, TTableName, TTableDescriptor, TColumnFamilyDescriptor, TNamespaceDescriptor, TGet, TPut, TScan
    # Configure the endpoint for LindormTable.
    url = "http://ld-bp17j28j2y7pm****-proxy-lindorm.lindorm.rds.aliyuncs.com:9190"
    transport = THttpClient.THttpClient(url)
    headers = {}
    # Set the username.
    headers["ACCESSKEYID"]="testuser";
    # Set the password for the username.
    headers["ACCESSSIGNATURE"]="password"
    transport.setCustomHeaders(headers)
    protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
    client = THBaseService.Client(protocol)
    transport.open()
    # Close the connection after completing the operations.
    transport.close()

Code samples

Complete code samples for other non-Java languages are available at the following GitHub links.