1. Configure the HBase 2.x environment
Here, because it is just to test the use of HBase's Java API, I only deployed a stand-alone version of the service in the local virtual machine, and the production environment can deploy the cluster mode by itself. It should also be noted that some of the listening ports of the stand-alone version of the HBase service are bound to the 127.0.0.1 of the virtual machine, which makes it impossible to connect to HBase using the Java API on the physical machine. My solution is to use SecureCRT to configure the relevant port mapping, the specific mapping information is as follows:
2. Detailed explanation of using the latest Java API to operate HBase 2.x
(1) Add the following dependencies to the Spring Boot/Spring Cloud project:
(2) Basic operations related to HBase:
(3) Add HBase configuration information:
The specific attributes used are as follows:
(4) Test the above basic methods:
i) Deleting, creating tables, and basic queries:
After running the unit tests, the output is as follows:
ii) Query that specifies startRowKey and stopRowKey:
This query is generally used when the RowKey is continuously incremented and only a part of the data is queried (such as pagination):
After running the unit tests, the output is as follows:
iii) Get all table names:
After running the unit tests, the output is as follows:
iv) Get data for multiple versions of a specified cell:
After running the unit tests, the output is as follows:
Note: Because HBase only saves one version by default, the effect is not visible here.
v) Query data based on row key filters:
After running the unit tests, the output is as follows:
vi) Query data based on column name filter:
After running the unit tests, the output is as follows:
vii) Query data containing specific characters in row keys:
After running the unit tests, the output is as follows:
viii) Delete the specified column:
After running the unit tests, the output is as follows:
ix) Delete the specified line:
After running the unit tests, the output is as follows:
According to the output, it can be seen that this line of data has indeed been deleted.
x) Delete the specified column family:
After running the unit tests, the output is as follows:
According to the output, it can be found that the column family "back" has been deleted.
|