HBase Data Read/Write Sample Program Development Roadmap
Scenario
Develop an application to manage information about users who use service A in an enterprise. Table 1 provides the user information. The operation process of service A is described as follows:
- Create a user information table.
- Add diplomas and titles to the user information table.
- Query user names and addresses by user ID.
- Query information by user name.
- Query information about users whose ages range from 20 to 29.
- Collect statistics on the number and the maximum, minimum, and average ages of users.
- Deregister users, and delete user data.
- Delete the user information table after service A ends.
Table 1 User information ID
Name
Gender
Age
Address
12005000201
Zhang San
Male
19
Shenzhen, Guangdong
12005000202
Li Wanting
Female
23
Shijiazhuang, Hebei
12005000203
Wang Ming
Male
26
Ningbo, Zhejiang
12005000204
Li Gang
Male
18
Xiangyang, Hubei
12005000205
Zhao Enru
Female
21
Shangrao, Jiangxi
12005000206
Chen Long
Male
32
Zhuzhou, Hunan
12005000207
Zhou Wei
Female
29
Nanyang, Henan
12005000208
Yang Yiwen
Female
30
Kaixian, Chongqing
12005000209
Xu Bing
Male
26
Weinan, Shaanxi
12005000210
Xiao Kai
Male
25
Dalian, Liaoning
Data Planning
Proper design of the table structure, RowKeys, and column names can give full play to the advantages of HBase. In this example, the unique ID is used as the RowKey, and columns are stored in the info column family.

HBase tables are stored in Namespace:Table name format. If no namespace is specified when a table is created, the table is stored in default. The hbase namespace is the system table namespace. Do not create service tables or read or write data in the system table namespace.
Function Decomposition
Functions are decomposed based on the preceding service scenario. Table 2 provides the functions to be developed.
No. |
Procedure |
Code Implementation |
---|---|---|
1 |
Create a table based on Table 1. |
For details, see Creating an HBase Table. |
2 |
Import user data. |
For details, see Inserting Data into the HBase Table. |
3 |
Add the Education column family, and add diplomas and titles to the user information table. |
For details, see Modifying an HBase Table. |
4 |
Query user names and addresses by user ID. |
For details, see Reading HBase Table Data Using Get. |
5 |
Query information by user name. |
For details, see Reading HBase Table Data Using Filter. |
6 |
To improve query performance, create or delete secondary indexes. |
For details, see Creating an HBase Secondary IndexandQuerying HBase Table Data Based on Secondary Indexes. |
7 |
Deregister users, and delete user data. |
For details, see Deleting HBase Table Data. |
8 |
Delete the user information table after service A ends. |
For details, see Deleting an HBase Table. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot