Basic usage of HBase shell
HBase provides a shell terminal to interact with the user. Use the command hbase Shell to enter the command interface. You can see the Help information for the command by performing a helper.
Demonstrate the use of hbase with an example of an online Student score table.
name |
Grad |
Course |
Math |
Art |
Tom |
5 |
97 |
87 |
Jim |
4 |
89 |
80 |
Here grad for the table is a only its own column family, course for the table is a column family of two columns, the column family consists of two columns math and art, of course, we can according to our needs in the course to build more column family, such as computer, Add the course column family to the corresponding columns such as physics.
(1) To establish a table scores, there are two grad and Courese codes for the column families as follows:
You can use the list command to see which tables are in the current hbase. Use the describe command to view the table structure. (Remember all the indications, the column names need to be quoted)
(2) Insert values according to the design table structure:
The code is as follows:
Put ' scores ', ' Tom ', ' Grade: ', ' 5′
put ' scores ', ' Tom ', ' Course:math ', ' 97′
put ' scores ', ' Tom ', ' Course:art ', ' 87
put ' scores ', ' Jim ', ' Grade ', ' 4′
put ' scores ', ' Jim ', ' Course: ', ' 89′
So the table structure is up, in fact, relatively free, column family inside can be free to add the child column is very convenient. If there are no child columns under the column family, it is possible to add no colons.
The put command is relatively simple, with only one usage:
T1 refers to the table name, R1 refers to the row key name, C1 refers to the column name, value refers to the cell value. Ts1 refers to the time stamp, which is generally omitted.
(3) Querying data based on key values
Get ' scores ', ' Jim '
You may find the rule, hbase shell operations, a general order is the operation of keywords followed by table name, row name, column name, such as a sequence, if there are other conditions with curly braces plus.
Get has the following usage:
Hbase> get ' t1′, ' r1′
hbase> get ' t1′, ' r1′, {timerange = [Ts1, ts2]}
hbase> get ' t1′, ' r1′, {COLUMN = = ' c1′}
hbase> get ' t1′, ' r1′, {column = [' C1 ', ' C2 ', ' C3 ']}
hbase> get ' t1′, ' r1′, {column = ' C 1′, TIMESTAMP = ts1}
hbase> get ' t1′, ' r1′, {COLUMN = ' c1′, Timerange = [Ts1, ts2], VERSIONS = 4}
hbase> get ' t1′, ' r1′, {COLUMN = ' c1′, TIMESTAMP = ts1, VERSIONS = 4}
hbase> get ' t1′, ' r1′, ' c1′
hbase> get ' t1′, ' r1′, ' c1′, ' c2′
(4) Scan all data
You can also specify some modifiers: Timerange, FILTER, LIMIT, StartRow, Stoprow, TIMESTAMP, Maxlength,or COLUMNS. No modifier, just the top example, will show all rows of data.
Examples are as follows:
The code is as follows:
Hbase> Scan '. META. '
Hbase> Scan '. META. ', {COLUMNS = ' info:regioninfo '}
hbase> scan ' t1′, {COLUMNS = [' C1 ', ' C2 '], LIMIT = ten, StartRow = > ' xyz '}
hbase> scan ' t1′, {COLUMNS = ' c1′, Timerange = [1303668804, 1303668904]}
hbase> scan ' t1 (Prefixfilter (' row2′) and (Qualifierfilter (>=, ' binary:xyz ')) and (Timestampsfilter (123, 456)) "}
Filter filters There are two ways to indicate:
A. Using a filterstring–more information on this is available in the
Filter Language document attached to the HBASE-4176 JIRA
B. Using the entire package name of the filter.
There is also a cache_blocks modifier, the cache of the switch scan, the default is on (cache_blocks=>true), you can choose to close (Cache_blocks=>false).
(5) Delete the specified data
The code is as follows:
Delete ' scores ', ' Jim ', ' Grade '
The delete data command does not change much, only one:
There is also a DeleteAll command, you can do the whole line of the scope of the deletion operation, with caution.
If you need to do a full table delete operation, use the TRUNCATE command, in fact, there is no direct full table Delete command, this command is also disable,drop,create three command combination.
(6) Modify table structure
The code is as follows:
Disable ' scores '
alter ' scores ',name=> ' info '
The ALTER command uses the following (if the version is not successful, the universal table disable is required first):
A, change or add a family of columns:
B. Delete a column family:
The code is as follows:
Hbase> Alter ' t1′, NAME = ' f1′, METHOD = ' delete '
C, you can also modify table properties such as Max_filesize
Memstore_flushsize, READONLY, and Deferred_log_flush:
D, you can add a table co-processor
Multiple co-processors can be configured on a single table, and a sequence is automatically grown for identification. Loading a co-processor (which can be said to be a filtering program) requires the following rules:
E, remove coprocessor as follows:
Hbase> Alter ' t1′, METHOD = ' Table_att_unset ', NAME = ' max_filesize '
F, you can execute multiple ALTER commands at once:
(7) Statistics of rows:
The code is as follows:
hbase> count ' t1′
hbase> count ' t1′, INTERVAL = 100000
hbase> count ' t1′, CACHE = 1000
Count is typically time consuming, using MapReduce for statistics, and the results are cached, with 10 rows by default. The statistical interval defaults to 1000 rows (INTERVAL).
(8) Disable and enable operation
Many operations need to pause the availability of the table first, such as the alter operation above, and the deletion of the table. Disable_all and Enable_all are able to manipulate more tables.
(9) Deletion of tables
Stop the table's usability before you execute the delete command.
The above is a few common commands in detail, the specific all hbase shell commands are as follows, divided into several command groups, to see the English is probably useful, detailed usage using help "cmd" to understand.
The code is as follows:
COMMAND GROUPS:
group name:general
commands:status, version
Group name:ddl
commands:alter, Alter_ Async, Alter_status, create, describe, disable, disable_all, drop, Drop_all,
Enable, Enable_all, exists, is_disabled , is_enabled, list, show_filters
Group name:dml
commands:count, delete, DeleteAll, get, Get_counter, incr, put, Scan, truncate
Group name:tools
commands:assign, Balance_switch, balancer, close_region, compact, flush, Hlog_ Roll, Major_compact,
move, Split, Unassign, Zk_dump
Group name:replication
commands:add_peer, Disable_ Peer, Enable_peer, List_peers, Remove_peer, start_replication,
stop_replication
Group name:security