HBase provides a shell terminal to interact with the user. Use the command Hbaseshell 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) Establish a table scores, there are two column families grad and couresehbase (main):001:0> create ' scores ', ' Grade ', ' course ' 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 by Design table structure: 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:math ', ' 89 '
Put ' scores ', ' Jim ', ' course:art ', ' 80 ' so the table structure is up, in fact, relatively free, the 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, only one usage: hbase> put ' t1 ', ' R1 ', ' C1 ', ' value ', ts1 T1 refers to the table name, R1 refers to the row key name, C1 refers to the column name, and value refers to the cell value. Ts1 refers to the time stamp, which is generally omitted. |
(3) Query data by key value get ' scores ', ' Jim '
Get ' scores ', ' Jim ', ' Grade ' Get ' scores ', ' Jim ', ' Course ' (the column family has multiple columns to use scan to get all the records "scan ' scores ', {COLUMNS = ' course '}", Get only a record of the newest addition to the column family with get) get ' scores ', ' Jim ', ' Course:math ' (that's OK) you may find the rule, hbase shell operation, a general order is the Operation keyword followed by the table name, row name, column name such a sequence , and if there are other conditions, add them with curly braces.
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 = ' 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) Scans all data scan ' scores ' 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: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 ', {FILTER = ' (Prefixfilter (' Row2 ') and (Qualifierfilter (>=, ' binary:xyz '))) and (Timestampsfil TER (123, 456)) "}
hbase> scan ' T1 ', {filter =>org.apache.hadoop.hbase.filter.columnpaginationfilter.new (1, 0)} Filters there are two ways of saying:
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, which switches the cache of the scan, which is enabled by default (Cache_blocks=>true), You can choose to close (Cache_blocks=>false). (5) Delete the specified data delete ' scores ', ' Jim ', ' Grade '
Delete ' scores ', ' Jim ' delete data command also not much change, only a:hbase> delete ' T1 ', ' R1 ', ' C1 ', Ts1 also has a deleteall command, you can do the whole line of the scope of the deletion operation, use 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 disable ' scores '
Alter ' scores ',name=> ' info '
The Enable ' scores ' ALTER command uses the following (if not successful version, the first universal table disable is required):
A, change or add a column family:hbase> alter ' T1 ', name=> ' F1 ', VERSIONS = 5b, delete a column family:hbase> alter ' T1 ', name=> ' F1 ', METHOD =& Gt ' Delete '
hbase> alter ' t1 ', ' delete ' \ = ' F1 ' C, can also modify table properties such as Max_filesize
Memstore_flushsize, READONLY, and Deferred_log_flush:
hbase> alter ' t1 ', METHOD = ' Table_att ', max_filesize = ' 134217728 '
D, can add a table co-processor hbase> alter ' T1 ', method=> ' Table_att ', ' coprocessor ' = ' hdfs:///foo.jar| ' com.foo.fooregionobserver|1001|arg1=1,arg2=2 ' A table can be configured with multiple co-processors, and a sequence will automatically grow for identification. Loading a co-processor (which can be said to be a filtering program) requires the following rules: [coprocessor jar filelocation] | 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, can execute multiple ALTER commands at once:hbase> alter ' T1 ', { Name=> ' F1 '}, {NAME = ' F2 ', METHOD = ' Delete '} (7) count the number of rows:hbase> ' T1 '
hbase> count ' t1 ', INTERVAL = 100000
hbase> count ' t1 ', CACHE = 1000
hbase> count ' t1 ', INTERVAL =, the cache = 1000count is typically time consuming, using MapReduce for statistics, the results are cached, and the default is 10 rows. 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. Drop ' T1 ' above is a few common commands in detail, the specific all hbase shell commands are as follows, a few command groups, to see the English is probably useful, detailed usage using help "cmd" to understand. 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:to OLS 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_r Eplication,stop_replication Group name:security Commands:grant,revoke, User_permission4. HBase Shell Script
Since it is a shell command, it is also possible to write all the Hbaseshell commands to a file and execute all commands sequentially, like the Linux shell script. Like writing Linuxshell, write all the Hbaseshell commands in a file, then execute the following command: $ hbase Shell Test.hbaseshell easy to use. For more highlights, please pay attention to: http://bbs.superwu.cn attention to Superman academy QR Code:
Basic usage of HBase shell