Hbase shell basics and Common commands)

Source: Internet
Author: User
Basic usage of hbase Shell

Hbase provides a shell terminal for user interaction. Run the hbase shell command to enter the command interface. Run the HELP command to view the help information of the command.

The usage of hbase is demonstrated using an example of an online student sequence table.

Name Grad Course
Math Art
Tom 5 97 87
Jim 4 89 80

Here, grad is a column family only for a table. course is a column family with two columns for the table. This column family consists of two columns: Math and art, of course, we can create more columns in course as needed, such as computer and physics, and add columns to the course columnfamily.

(1) create a table scores with two columnfamilies grad and courese

The Code is as follows:
hbase(main):001:0> create ‘scores‘,‘grade‘, ‘course‘ 

You can use the LIST command to view the tables in the current hbase. Use the describe command to view the table structure. (Remember to enclose all the representations and column names with quotation marks)

(2) Insert values based on the designed 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′ put ‘scores‘,‘Jim‘,‘course:‘,‘80′ 
In this way, the table structure becomes more free. It is very convenient to add sub-columns freely in the column family. If there are no child columns in the column family, you can add a colon without adding it.

The PUT command is relatively simple. only use this method:
hbase> put ‘t1′, ‘r1′, ‘c1′, ‘value‘, ts1 

T1 indicates the table name, R1 indicates the row key name, C1 indicates the column name, and value indicates the cell value. Ts1 indicates the timestamp, which is generally omitted.

(3) querying data based on key values
get ‘scores‘,‘Jim‘ get ‘scores‘,‘Jim‘,‘grade‘ 
You may find the rule. an approximate sequence of hbase shell operations is the sequence of Operation keywords followed by table name, row name, and column name. If there are other conditions, add them in curly brackets.
The get method is as follows:
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 => ‘c1′, 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′ hbase> get ‘t1′, ‘r1′, [‘c1‘, ‘c2‘] 
(4) scan all data
scan ‘scores‘ 
You can also specify modifiers: timerange, filter, limit, startrow, stoprow, timestamp, maxlength, or columns. There is no modifier, that is, the above example, all data rows will be displayed.

Example:
The Code is as follows:
hbase> scan ‘.META.‘ hbase> scan ‘.META.‘, {COLUMNS => ‘info:regioninfo‘} hbase> scan ‘t1′, {COLUMNS => [‘c1‘, ‘c2‘], LIMIT => 10, STARTROW => ‘xyz‘} hbase> scan ‘t1′, {COLUMNS => ‘c1′, TIMERANGE => [1303668804, 1303668904]} hbase> scan ‘t1′, {FILTER => “(PrefixFilter (‘row2′) AND (QualifierFilter (>=, ‘binary:xyz‘))) AND (TimestampsFilter ( 123, 456))”} hbase> scan ‘t1′, {FILTER => org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1, 0)} 
The filter has two methods:

A. Using a filterstring-more information on this is available in
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 that switches the scan cache. By default, it is enabled (cache_blocks => true). You can choose to disable it (cache_blocks => false ).

(5) delete specified data
The Code is as follows:
delete ‘scores‘,‘Jim‘,‘grade‘ delete ‘scores‘,‘Jim‘ 
The data deletion command does not change much either. There is only one:
hbase> delete ‘t1′, ‘r1′, ‘c1′, ts1 
In addition, there is a deleteall command, which can be used to delete the entire row range. Use it with caution!
If you need to delete a full table, use the truncate command. In fact, there is no direct full table deletion command. This command is also combined by the disable, drop, and create commands.

(6) modify the table structure
The Code is as follows:
disable ‘scores‘ alter ‘scores‘,NAME=>‘info‘ enable ‘scores‘ 
Run the alter command as follows (if the version cannot be successful, the general table disable must be used first ):
A. change or add a column family:
hbase> alter ‘t1′, NAME => ‘f1′, VERSIONS => 5 
B. delete a columnfamily:
The Code is as follows:
hbase> alter ‘t1′, NAME => ‘f1′, METHOD => ‘delete‘ hbase> alter ‘t1′, ‘delete‘ => ‘f1′ 
C. You can also modify table attributes such as max_filesize.
Memstore_flushsize, readonly, and deferred_log_flush: hbase> alter 't1', method => 'table _ ATT ', max_filesize => '123 ′
D. You can add a table coprocessor.
hbase> alter ‘t1′, METHOD => ‘table_att‘, ‘coprocessor‘=> ‘hdfs:///foo.jar|com.foo.FooRegionObserver|1001|arg1=1,arg2=2′ 
Multiple coprocessor can be configured for a table, and a sequence will automatically grow for identification. To load a coprocessor (a filter program), you must comply with the following rules:
[coprocessor jar file location] | class name | [priority] | [arguments] 
E. Remove coprocessor as follows:
hbase> alter ‘t1′, METHOD => ‘table_att_unset‘, NAME => ‘MAX_FILESIZE‘ hbase> alter ‘t1′, METHOD => ‘table_att_unset‘, NAME => ‘coprocessor$1′ 
F. Multiple alter commands can be executed at a time:
hbase> alter ‘t1′, {NAME => ‘f1′}, {NAME => ‘f2′, METHOD => ‘delete‘} 
(7) number of statistical rows:
The Code is as follows:
hbase> count ‘t1′ hbase> count ‘t1′, INTERVAL => 100000 hbase> count ‘t1′, CACHE => 1000 hbase> count ‘t1′, INTERVAL => 10, CACHE => 1000 
Count is generally time-consuming. mapreduce is used for statistics and the statistical results are cached. The default value is 10 rows. The default statistical interval is 1000 rows (interval ).

(8) Disable and enable Operations
In many operations, you need to suspend table availability first, such as the alter operation mentioned above. This operation is also required to delete a table. Disable_all and enable_all can operate more tables.

(9) delete a table
Stop the table's usability and run the DELETE command.
drop ‘t1′ 
The above is a detailed explanation of some common commands. The specific shell commands for all hbase are as follows, which are divided into several command groups. It can be seen that the commands are useful in English, use help "cmd" for detailed usage.

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 Commands: grant, revoke, user_permission 
  Hbase shell script
Since it is a shell command, of course, you can also write all hbase shell commands into a file and execute all commands in sequence like the Linux Shell script program. Like writing a Linux Shell, write all hbase shell commands in a file, and then execute the following command:
The Code is as follows:
$ hbase shell test.hbaseshell 
Easy to use. From http://www.jb51.net/article/31172.htm

Hbase shell basics and Common commands)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.