Basic commands and examples of hbase
👉 Note: wrong hbase command can be deleted by ctrl+backspace
ddl command
1. Create table
// Direct tabulation create 'Table name',{NAME => 'Family name 1'},{NAME => 'Family name 2'} ... // Short form create 'Table name','Family name 1','Family name 2'..... hbase(main):002:0> create 'jzydemo','base' 0 row(s) in 2.2930 seconds => Hbase::Table - jzydemo // Chestnut: create 'jzydemo','base'
2. Add column family
// To add a new column family format to an existing table: alter 'Table name','Add family name' // Chestnut: alter 'jzydemo','external'
3. Delete a column family
// Curly brackets can be omitted for format shorthand alter 'Table name',{NAME=>'Need to delete column family name', METHOD=>'delete'} // Chestnut: alter 'jzydemo',NAME=>'base',METHOD=>'delete'
4. View table structure
describe 'table name'
Chestnut: jzydemo structure of table created in query 1
5. Check whether the table exists
exists' table name '
6. Delete table
drop 'table name'
Before deleting a table, disable the table. Instead, enable the table
Example:
- disable 'jzydemo'
- drop 'mydemo'
Create a tablespace and create tables under it
1. Create a tablespace
create_namespace 'tablespace name'
Example:
create_namespace 'jzyspace'
2. Create table in table space
create 'tablespace Name: table name', 'column family name'
create 'jzyspace:userinfos','base' create 'jzyspace:score','total'
3. View the table under tablespace
list_namespace_tables' tablespace name '
dml command
1. Insert data
// Format: put 'Table name','Row key','To name a family','Column value' put 'Table name','Row key','To name a family:Column name','Column value' // Chestnut: put 'jzyspace:userinfos','1','base:username','zhangsan'
2. Full table scanning
- View all data in table scan 'table name'
- View a column family scan 'table name', {column = > 'column family name'}
- View multiple column families scan 'table name', {column = > ['column family name 1 ','column family name 2']...}
- View a column of a column family scan 'table name', {column = > 'column family name: column name'}
- View multiple columns under multiple column families scan 'table name', {column = > ['column family name 1: column name 1', 'column family name 1: column name 2', 'column family name 2: column name 21', 'column family name 2: column name 22']...}
Use of filter to find filter
List several commonly used filter s:
ColumnPrefixFilter a lookup whose column prefix contains a character
PrefixFilter column prefix contains a character lookup
ValueFilter contains a value lookup
STARTROW searches backward from a value in the column family
STOPROW finds that the column family ends with a value
Example:
// Contents with a value of 23 in the lookup table hbase(main):045:0> scan 'jzyspace:userinfos',FILTER=>"ValueFilter(=,'binary:23')" ROW COLUMN+CELL 1 column=external:age, timestamp=1593078115280, value=23 1 row(s) in 0.0160 seconds // The prefix of the column name in the lookup table is username, and the value contains the content of the san field hbase(main):043:0> scan 'jzyspace:userinfos',FILTER=>"ColumnPrefixFilter('username')AND ValueFilter(=,'substring:san')" ROW COLUMN+CELL 1 column=base:username, timestamp=1593074706538, value=zhangsan 1 row(s) in 0.0330 seconds // Find content with a value of 23 from the beginning of column family 1 hbase(main):046:0> scan 'jzyspace:userinfos',STARTROW=>'1',FILTER=>"ValueFilter(=,'binary:23')" ROW COLUMN+CELL 1 column=external:age, timestamp=1593078115280, value=23 1 row(s) in 0.0090 seconds
3. Access to data
- Get a row of data get 'table name', 'row key'
- Get a row a column family data get 'table name', 'row key', 'column family name'
- Get data according to multiple conditions' get 'table name', 'row key', {condition 1 = [1jeemaa1], condition 2 = [1jeemaa1]...}
4. Delete data
- Delete the value of a row and a column delete 'table name', 'row key', 'column family name: column name'
- Delete a row of data delete all 'table name', 'row key'
5. Count lines
count 'table name'
6. Add auto add column
👉🏻 Note: adding an auto add column to the same column repeatedly will add + 1 on the original basis
//format incr 'Table name','Row key','To name a family:Column family',Step value //Chestnut: incr 'jzyspace:userinfos','1','base:stuno',1
7. Find the content of limit lines
scan 'table name', {limit = > number of rows}
It can be used in combination with STARTROW for paging
Practice more ✌🏻 Practice makes perfect!!! 🐱 A kind of 👤