1. Basic commands

Start Hbase Shell:

# hbase shell
Copy the code

1.1 Obtaining Help

#Get help
help
#Gets the details of the command
help 'status'
Copy the code

1.2 Checking the Server Status

status
Copy the code

1.3 Viewing the Version Information

version
Copy the code

Second, about the table operation

2.1 Viewing all tables

list
Copy the code

2.2 create a table

Create ‘table name ‘,’ column family name 1′,’ column family name 2′,’ column name N’

#Create a table named Student with two column families: baseInfo and schoolInfo
create 'Student','baseInfo','schoolInfo'
Copy the code

2.3 Viewing Basic Table Information

Command format: desc ‘table name’

describe 'Student'
Copy the code

2.4 Table enable/disable

Enable and disable enable/disable the table,is_enabled and is_disabled to check whether the table is disabled

#Disable the table
disable 'Student'
#Check whether the table is disabled
is_disabled 'Student'
#Enable the table
enable 'Student'
#Check whether the table is enabled
is_enabled 'Student'
Copy the code

2.5 Checking whether the table exists

exists 'Student'
Copy the code

2.6 delete table

#You must disable a table before deleting it
disable 'Student'
#Delete table
drop 'Student'
Copy the code

Three, add, delete and change

3.1 Adding column families

Alter table name, column family name

alter 'Student', 'teacherInfo'
Copy the code

3.2 Deleting a column family

Alter ‘table NAME ‘, {NAME =>’ column family NAME ‘, METHOD => ‘delete’}

alter 'Student', {NAME => 'teacherInfo', METHOD => 'delete'}
Copy the code

3.3 Restrictions on changing the version of the column family store

By default, a column family stores only one version of data. If you want to store more than one version of data, you need to modify the attributes of the column family. After the modification, you can run the desc command to view it.

alter 'Student',{NAME=>'baseInfo',VERSIONS=>3}
Copy the code

3.4 Inserting Data

Syntax: put ‘table name ‘,’ row key ‘,’ column family: Column ‘,’ value’

Note: If the row key value, column family name and column name of the new data are exactly the same as the original data, it is equivalent to an update operation

put 'Student', 'rowkey1','baseInfo:name','tom'
put 'Student', 'rowkey1','baseInfo:birthday','1990-01-09'
put 'Student', 'rowkey1','baseInfo:age','29'
put 'Student', 'rowkey1','schoolInfo:name','Havard'
put 'Student', 'rowkey1','schoolInfo:localtion','Boston'

put 'Student', 'rowkey2','baseInfo:name','jack'
put 'Student', 'rowkey2','baseInfo:birthday','1998-08-22'
put 'Student', 'rowkey2','baseInfo:age','21'
put 'Student', 'rowkey2','schoolInfo:name','yale'
put 'Student', 'rowkey2','schoolInfo:localtion','New Haven'

put 'Student', 'rowkey3','baseInfo:name','maike'
put 'Student', 'rowkey3','baseInfo:birthday','1995-01-22'
put 'Student', 'rowkey3','baseInfo:age','24'
put 'Student', 'rowkey3','schoolInfo:name','yale'
put 'Student', 'rowkey3','schoolInfo:localtion','New Haven'

put 'Student', 'wrowkey4','baseInfo:name','maike-jack'
Copy the code

3.5 Obtain information about the specified row, column families, and columns in the specified row

#Gets data information for all columns in the specified row
get 'Student','rowkey3'
#Gets data information for all columns under the specified column family in the specified row
get 'Student','rowkey3','baseInfo'
#Gets data information for the specified column in the specified row
get 'Student','rowkey3','baseInfo:name'
Copy the code

3.6 Deleting the specified row and columns in the specified row

#Delete the specified row
delete 'Student','rowkey3'
#Deletes data for the specified column in the specified row
delete 'Student','rowkey3','baseInfo:name'
Copy the code

Fourth, the query

Hbase data can be accessed in two basic modes:

  • To get data by the specified rowkey: get method;

  • Obtain data by specified criteria: Scan method.

Scan can set begin and end parameters to access all data in a range. Get is essentially a special scan where begin and end are equal.

4.1 Get queries

#Gets data information for all columns in the specified row
get 'Student','rowkey3'
#Gets data information for all columns under the specified column family in the specified row
get 'Student','rowkey3','baseInfo'
#Gets data information for the specified column in the specified row
get 'Student','rowkey3','baseInfo:name'
Copy the code

4.2 Querying Data in the Entire Table

scan 'Student'
Copy the code

4.3 Querying the Data of a specified column cluster

scan 'Student', {COLUMN=>'baseInfo'}
Copy the code

4.4 Conditional Query

#Query data for the specified column
scan 'Student', {COLUMNS=> 'baseInfo:birthday'}
Copy the code

In addition to COLUMNS, HBase also supports Limit (limiting the number of rows in a query result) and STARTROW (starting row with ROWKEY. Region is located based on this key. Scan backward), STOPROW(end row), TIMERANGE (limit timestamp range), VERSIONS (version number), and FILTER (FILTER row by condition).

Start with rowKey2 and find the latest 3 versions of the name column for the next two rows:

scan 'Student', {COLUMNS=> 'baseInfo:name',STARTROW => 'rowkey2',STOPROW => 'wrowkey4',LIMIT=>2, VERSIONS=>3}
Copy the code

4.5 Conditional Filtering

Filter you can set a series of criteria for filtering. If we want to query all data with a value equal to 24:

scan 'Student', FILTER=>"ValueFilter(=,'binary:24')"
Copy the code

Value contains all data for Yale:

scan 'Student', FILTER=>"ValueFilter(=,'substring:yale')"
Copy the code

The column name prefix is birth:

scan 'Student', FILTER=>"ColumnPrefixFilter('birth')"
Copy the code

Multiple FILTER criteria can be combined by parentheses, AND, AND OR:

#The column name is prefixed with birth and the column value contains data from 1998
scan 'Student', FILTER=>"ColumnPrefixFilter('birth') AND ValueFilter ValueFilter(=,'substring:1998')"
Copy the code

PrefixFilter is used to determine the prefix of the Rowkey:

scan 'Student', FILTER=>"PrefixFilter('wr')"
Copy the code

See the GitHub Open Source Project: Getting Started with Big Data for more articles in the big Data series