HBase shell command create table and add data operation

Posted by delickate on Wed, 11 Dec 2019 22:08:13 +0100

Create a table with the NAME hbase_. The HBase table is composed of Key values. In this table, the Key is NAME
 


This table has two column families, CF1 and CF2. Under CF1 and CF2, there are two columns, name and gender, Chinese and Math
1. There are two column families CF1 and CF2 in creating table HBase

hbase(main):041:0> create 'hbase_1102',  {NAME=>'cf1'}, {NAME=>'cf2'}

2. Add data to the table. When you want to add data to the table of HBase, you can only add one column and one column, not multiple columns at the same time.

hbase(main):042:0> put'hbase_1102', '001','cf1:name','Tom'
hbase(main):043:0> put'hbase_1102', '001','cf1:gender','man'
hbase(main):044:0> put'hbase_1102', '001','cf2:chinese','90'
hbase(main):045:0> put'hbase_1102', '001','cf2:math','91'

 

In this way, the table structure is up. In fact, it is relatively free. It is very convenient to add child columns freely in the column family. If there is no child column under the column family, it is OK to add a colon or not.

If you need to set the time stamp manually when adding data, you need to add the corresponding time stamp at the end of the put command. The time stamp is of long type, so you don't need to use quotation marks

hbase(main):045:0> put'hbase_1102', '001','cf2:math','91',1478053832459

3. View all data in the table

hbase(main):046:0> scan 'hbase_1102'
ROW   COLUMN+CELL                                                             
 001  column=cf1:gender, timestamp=1478053832459, value=man                   
 001  column=cf1:name, timestamp=1478053787178, value=Tom                     
 001  column=cf2:chinese, timestamp=1478053848225, value=90001  column=cf2:math, timestamp=1478053858144, value=911 row(s) in0.0140seconds

4. View the data of one of the keys

hbase(main):048:0> get'hbase_1102','001'
COLUMN                    CELL                                                                    
 cf1:gender               timestamp=1478053832459, value=man                                      
 cf1:name                 timestamp=1478053787178, value=Tom                                      
 cf2:chinese              timestamp=1478053848225, value=90                                       
 cf2:math                 timestamp=1478053858144, value=914 row(s) in0.0290seconds

Topics: Big Data HBase