HBase Series (five) - HBase Common Shell Commands

First, the basic command

Open Hbase Shell:

# hbase shell

1.1 Getting Help

# 获取帮助
help
# 获取命令的详细信息
help 'status'

1.2 View server status

status

1.3 Version information

version

Second, the operation on the table

Table 2.1 View all

list

2.2 Creating table

Syntax : create 'table name', 'Group name column 1', '2 column family name', 'column name N'

# 创建一张名为Student的表,包含基本信息(baseInfo)、学校信息(schoolInfo)两个列族
create 'Student','baseInfo','schoolInfo'

2.3 view basic information table

Format : desc 'table name'

describe 'Student'

Table 2.4 enabled / disabled

enable and disable You can enable / disable whether this table, is_enabled and is_disabled to be disabled checklist

# 禁用表
disable 'Student'
# 检查表是否被禁用
is_disabled 'Student'
# 启用表
enable 'Student'
# 检查表是否被启用
is_enabled 'Student'

2.5 Check the table exists

exists 'Student'

2.6 Delete table

# 删除表前需要先禁用表
disable 'Student'
# 删除表
drop 'Student'

Third, additions and deletions

3.1 Add Column Family

Format : alter 'table', 'Group name column'

alter 'Student', 'teacherInfo'

3.2 Delete column family

Format : alter 'table', {NAME => 'Group name column', METHOD => 'delete' }

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

Change the column family version 3.3 storage limit

By default, only the column group storing a version of the data, if necessary to store multiple versions of the data, the need to modify the properties of the column group. After modification can descview the command.

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

3.4 Insert Data

Format : PUT 'table', 'OK button', 'Group columns: column', 'value'

Note: If the new data row key, column family names, column names are identical with the original data, the equivalent update

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'

3.5 Gets the specified row, column family in the specified row and column information

# 获取指定行中所有列的数据信息
get 'Student','rowkey3'
# 获取指定行中指定列族下所有列的数据信息
get 'Student','rowkey3','baseInfo'
# 获取指定行中指定列的数据信息
get 'Student','rowkey3','baseInfo:name'

3.6 delete the specified line, specify the column in a row

# 删除指定行
delete 'Student','rowkey3'
# 删除指定行中指定列的数据
delete 'Student','rowkey3','baseInfo:name'

Fourth, the query

hbase access data in two basic ways:

  • Get data specified rowkey: get method;

  • Obtaining data specified conditions: scan method.

scanBegin and end parameters can be provided to access all the data within a range. Get on essentially equal to begin and end a special scan.

4.1Get inquiry

# 获取指定行中所有列的数据信息
get 'Student','rowkey3'
# 获取指定行中指定列族下所有列的数据信息
get 'Student','rowkey3','baseInfo'
# 获取指定行中指定列的数据信息
get 'Student','rowkey3','baseInfo:name'

4.2 queries the entire data table

scan 'Student'

4.3 query specifies column clusters of data

scan 'Student', {COLUMN=>'baseInfo'}

4.4 Conditions inquiry

# 查询指定列的数据
scan 'Student', {COLUMNS=> 'baseInfo:birthday'}

In addition to the column (COLUMNS)qualifier outside, HBase supports Limit(to limit the number of rows of query results), STARTROW( ROWKEYstart line, this will be the first based on keypositioned region, again after scanning), STOPROW(end of line), TIMERANGE(timestamp limited range), VERSIONS(version number ), and FILTER(conditional line filter) and the like.

As representatives from rowkey2the rowkeybeginning, to find the latest version under three rows of two columns of data name:

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

4.5 Conditions filter

Filter range of conditions can be set to filter. If we want to query the value of all data is equal to 24:

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

Yale value contains all the data:

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

Prefix the column name for the birth of:

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

FILTER supported by a plurality of bracket combining filter conditions, AND, and OR:

# 列名中的前缀为birth且列值中包含1998的数据
scan 'Student', FILTER=>"ColumnPrefixFilter('birth') AND ValueFilter ValueFilter(=,'substring:1998')"

PrefixFilter Rowkey prefix for the determination of:

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

More big data series can be found GitHub open source project : Big Data Getting Started

Guess you like

Origin www.cnblogs.com/heibaiying/p/11406896.html