ApsaraDB for HBase allows you to use Hive to read and write a table.
- Before you perform this task, you must add the IP addresses of all the nodes in the Hadoop cluster where Hive runs to the whitelist of ApsaraDB for HBase.
- Retrieve the ZooKeeper endpoint of ApsaraDB for HBase. You can find the endpoint in the ApsaraDB for HBase console.
## Modify the configuration
- Switch to the Hive configuration directory
/etc/ecm/hive-conf/
. - Open the
hbase-site.xml
file and set the value of thehbase.zookeeper.quorum
parameter to the ZooKeeper endpoint of ApsaraDB for HBase.
<property>
<name>hbase.zookeeper.quorum</name>
<value>hb-xxx-001.hbase.rds.aliyuncs.com,hb-xxx-002.hbase.rds.aliyuncs.com,hb-xxx-003.hbase.rds.aliyuncs.com</value>
</property>
Read and write an ApsaraDB for HBase table in Hive
If you have not created a table in ApsaraDB for HBase, you can create an external table for ApsaraDB for HBase in Hive.
- Launch Hive CLI

- Create a Hive external table for ApsaraDB for HBase.
CREATE TABLE hive_hbase_table(key int, value string)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val")
TBLPROPERTIES ("hbase.table.name" = "hive_hbase_table", "hbase.mapred.output.outputtable" = "hive_hbase_table");
- Insert data to the table in Hive.
insert into hive_hbase_table values(212,'bab');

- A same table is created in ApsaraDB for HBase, and the same data is inserted into
the table.
-
Insert data into the table in ApsaraDB for HBase, and show the table in Hive.
Show the table in Hive:
-
If you delete the external table in Hive, the associated table in ApsaraDB for HBase is also deleted.
Show the table in ApsaraDB for HBase. An error message is displayed indicating that the table does not exist.
If you have already created a table in ApsaraDB for HBase before you create the external table, you can associate the external table with the table in ApsaraDB for HBase. In this case, if you delete the external table in Hive, the table in ApsaraDB for HBase will not be deleted.
- Create a table in ApsaraDB for HBase, and insert data into the table.
- Create an external table in Hive, associate it with the table in ApsaraDB for HBase,
and show the external table.
-
If you delete the external table in Hive, the table in ApsaraDB for HBase will not be deleted.
For more information about how to use Hive to interact with ApsaraDB for HBase, visit https://cwiki.apache.org/confluence/display/Hive/HBaseIntegration.
If you are using a Hive service running in a MapReduce cluster deployed on an Elastic
Compute Service (ECS) instance, you can use Hive to interact with ApsaraDB for HBase
in the same way as using a Hive service running in an E-MapReduce cluster. However,
some of the configurations in the Hive configuration file hbase-site.xml are different
from those of ApsaraDB for HBase. In this case, you only need to ensure that the hbase.zookeeper.quorum
settings are consistent.