HBase tables are way different compared to the relational database tables. HBase organizes all data into tables. Table names are Strings and composed of characters that are easy and safe for use in a file system path. In this article, we will check create tables using HBase shell commands and examples.
We will create the sample tables will couple of columns and insert some sample values to verify the tables.
Create Tables using HBase Shell
You can create a table using the create command in HBase, table name and the Column Family name are mandatory fields to create table. All the columns in the HBase are grouped into column family.
Related Reading:
The HBase data model design for the table is given below:
RowKey | personal_data:name | personal_data:city | personal_data:age |
1 | Ram | Bengaluru | 25 |
Syntax to Create Tables using HBase Shell
The syntax to create table in HBase shell is given below:
create '<table_name>', '<column_family_name>'
Split HBase Table
You can pre-split HBase table when you initially create it.
You can read more on HBase table splitting in other post:
Create Tables using HBase Shell Example
Below is the examples of creating ‘personal’ table with column family name personal_data:name, personal_data:city and personal_data:age:
hbase(main):031:0> create 'personal','personal_data' 0 row(s) in 2.3850 seconds => Hbase::Table - personal
Check Created HBase Table
You can check if the table created using ‘list’ command. Below is the sample output of the list command when executed by passing above created table name as argument:
hbase(main):035:0> list 'personal' TABLE personal 1 row(s) in 0.0080 seconds => ["personal"]
You can also keep the versions of the column. You need to specify the number of column versions to be kept while creating tables.
You can read more on HBase column versioning on other post:
Insert sample records to the HBase table
For now to test your created table, follow below steps to insert records to HBase table:
hbase(main):037:0> put 'personal',1,'personal_data:name','Ram' 0 row(s) in 0.0230 seconds hbase(main):038:0> put 'personal',1,'personal_data:city','Bengaluru' 0 row(s) in 0.0050 seconds hbase(main):039:0> put 'personal',1,'personal_data:age','25' 0 row(s) in 0.0030 seconds
Display the Content of HBase Table
You can use the ‘scan’ command to display the content of tables. Follow below step:
hbase(main):040:0> scan 'personal' ROW COLUMN+CELL 1 column=personal_data:age, timestamp=1505200304953, value=25 1 column=personal_data:city, timestamp=1505200291903, value=Bengaluru 1 column=personal_data:name, timestamp=1505200278059, value=Ram 1 row(s) in 0.0090 seconds hbase(main):041:0>
Read:
- Alter HBase Table using shell command and Examples
- HBase Delete Row using HBase shell Command and Examples
- Read HBase Table using HBase shell get Command
- Insert data using HBase shell put Command
- Official Apache HBase documentation
- Commonly used General Hbase Shell Commands