You can use the ApsaraDB for HBase API for a non-Java language, such as C++, Python, and Go, to connect to the wide table engine LindormTable. This topic describes how to install and use ApsaraDB for HBase SDK for a non-Java language.

Background information

LindormTable uses Thrift to allow you to use ApsaraDB for HBase SDK for a non-Java language, such as C++, Python, and Go, to connect to LindormTable.

LindormTable uses Thrift2 interface definition for ApsaraDB for HBase. You must download the Thrift2 definition file for ApsaraDB for HBase to generate an interface definition language (IDL) file in the corresponding language. Thrift2 interface definition for ApsaraDB for HBase used by LindormTable is clearer than Thrift1 interface definition for ApsaraDB for HBase. You can call an API operation for a non-Java language in a similar manner as you call an API operation for Java. The Thrift2 definition file for ApsaraDB for HBase provides more features and easier-to-use features than the Thrift1 definition file for ApsaraDB for HBase.

Prerequisites

Use ApsaraDB for HBase SDK for a non-Java language, such as Python, to connect to LindormTable

For information about how to install Thrift by using the Thrift installation package, see the Apache Thrift official documentation. You can perform the following steps to use Thrift to connect to LindormTable:
  1. Execute the following statement to use the Thrift2 definition file for ApsaraDB for HBase to generate an IDL file in the corresponding language.
    thrift --gen <language> hbase.thrift
    Note The language parameter specifies the programming language that you want to use. You can set this parameter to a value, such as python, php, cpp, and py.
    The following code shows a sample statement:
    thrift --gen python hbase.thrift
  2. Create a client to connect to LindormTable.
    The Thrift server in Lindorm uses HTTP in the transport layer. The ThttpClient of Thrift is required when you create a client. The method of creating the client varies based on the languages. If the Access Control List (ACL) is enabled, specify the username and password in two headers in the ThttpClient for authentication. The username and password are not required if ACL is disabled. Thrift allows you to call a function for a language to specify a custom header in ThttpClient. In the following example, Python is used. You can execute the following statements to create a client and connect to LindormTable:
     # -*- coding: utf-8  -*-
     # You can run the pip install thrift command to generate the following two modules:
     from thrift.protocol import TBinaryProtocol
     from thrift.transport import THttpClient
    
     # You can run the thrift --gen py hbase.thrift command to generate the following two modules:
     from hbase import THBaseService
     from hbase.ttypes import TColumnValue, TColumn, TTableName, TTableDescriptor, TColumnFamilyDescriptor, TNamespaceDescriptor, TGet, TPut, TScan
    
     # Specify the endpoint of LindormTable.
     url = "http://ld-bp17j28j2y7pm****-proxy-lindorm.lindorm.rds.aliyuncs.com:9190"
     transport = THttpClient.THttpClient(url)
     headers = {}
     # Specify the username.
     headers["ACCESSKEYID"]="testuser";
     # Specify the password that corresponds to the username.
     headers["ACCESSSIGNATURE"]="password"
     transport.setCustomHeaders(headers)
     protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
     client = THBaseService.Client(protocol)
     transport.open()
     # Close the connection.
     transport.close()

Sample code in other languages

To obtain complete sample code for other non-Java languages, click one of the following download links to download sample code for a language from GitHub: