If you use the HBase API, you can use Hive to connect to an ApsaraDB for Lindorm (Lindorm) cluster. You can perform the following steps:
  1. Replace the hbase-client JAR file in the hive/lib directory with the alihbase-client JAR file of the required version. You cannot delete the hive-hbase-handler-{version}.jar file because it contains the code that is used by Hive to connect to HBase. For more information, see Replace JAR files to upgrade your clients of earlier versions.
  2. Replace the loaded hbase-client JAR file with the alihbase-client JAR if the HBase dependencies are specified in --auxpath. You may specify the dependencies in the hive/.hiverc file or specify the dependencies when you start the Hive client.

Preparations

  • Obtain the endpoint of a Lindorm cluster
  • Obtain a username and its password
  • Add the IP address of the Hive client node to the whitelist of the Lindorm cluster

    You must add the IP address of the Hive client node to the whitelist of the Lindorm cluster. Otherwise, you cannot use Hive to connect to the Lindorm cluster.

Configure connection parameters in Hive

You can use one of the following two methods to configure connection parameters in Hive. If you want to configure the parameters in the hive-site.xml file, add the following configuration items to the file:

1.   <configuration>
2.      <!--
3.    Enter the endpoint of your Lindorm cluster. You can obtain the value on the Database Connection page in the Lindorm console. Use a public endpoint if you connect to the Lindorm cluster over the Internet. Use an internal endpoint if you connect to the Lindorm cluster over a virtual private cloud (VPC).
4.    -->
5.    <property>
6.        <name>hbase.zookeeper.quorum</name>
7.        <value>ld-xxxx-proxy-hbaseue.hbaseue.xxx.rds.aliyuncs.com:30020</value>
8.    </property>
9.    <!--    
10.   Specify the username and the password. By default, the username and the password are root. You can change them as needed.
11.    -->
12.    <property>
13.        <name>hbase.client.username</name>
14.        <value>root</value>
15.    </property>
16.    <property>
17.        <name>hbase.client.password</name>
18.        <value>root</value>
19.    </property>
20.  </configuration>

You can also run the following commands on the Hive client to configure the parameters:

1. set hbase.zookeeper.quorum=ld-xxxx-proxy-hbaseue.hbaseue.xxx.rds.aliyuncs.com:30020
2. set hbase.client.username=root
3. set hbase.client.password=root

After the parameters are configured, you can use the Hive client to connect to the Lindorm cluster.

Get started with Hive

This section describes how to get started with Hive. After you associate a table in Lindorm with Hive, the table is an external table for Hive. You can perform the following steps to use Hive to connect to a Lindorm cluster:

  • Open the Hive client.Open the Hive client.
  • Create a table in Lindorm.
    1. CREATE TABLE hive_hbase_table(key int, value string)
    2. STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
    3. WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val")
    4. TBLPROPERTIES ("hbase.table.name" = "hive_hbase_table", "hbase.mapred.output.outputtable" = "hive_hbase_table");
  • Use the Hive client to insert data into the table in Lindorm.
    1. insert into hive_hbase_table values(212,'bab');
    Insert data
  • Query the table that you create in Lindorm. You can view that the table is created and the data is inserted into the table. Query the table that you create
  • Insert data into the table in Lindorm and query the data in Hive. Query the inserted data
  • Query data in Hive.Query data
  • Delete the table. If you delete the table in Hive, the table in Lindorm is also deleted. Delete a table
  • Query the table in Lindorm. An error message appears. The message indicates that the table does not exist. Query the table
  • If the table is created in Lindorm, you can associate the created table with Hive. In this case, the table is an external table in Hive. If you delete the external table in Hive, the table in Lindorm will not be deleted.
  • Create a table in Lindorm and insert test data into the table. Create a test table
  • Create an external table in Hive and query the table data. The external table is associated with Lindorm. Query data
  • Delete the external table in Hive. This operation does not delete the associated table in Lindorm. Delete a table that you no longer use

For more information about how to use Hive to query a table in Lindorm, see More operations.

Notice You cannot use Hive to query underlying files in Lindorm. If you want to query data in Lindorm, you can create a table in Lindorm and associate the table with Hive. The associated table is an external table in Hive. This way, you can perform read and write operations on the external table in Hive.