Hbase basic sentence usage
Use the hbase shell command to enter hbase:
[root@abcdefghijklmnopqrstuvwxyzabcdefghijkl123456789012~] # hbase shellSLF4J: Class path contains multiple SLF4Jbindings.SLF4J: Found binding in [jar:file:/usr/hdp/2.4.3.0-227/hadoop/lib/slf4j-log4j12-1.7.10. Jarring Found binding in Found binding in [jar:file:/usr/hdp/2.4.3.0-227/zookeeper/lib/slf4j-log4j12-1.6.1.jarLogerBinder.class] SLF4J : See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.SLF4J: Actual binding is of type[org.slf4j.impl.Log4jLoggerFactory] HBase Shell Enter 'help' forlist of supported commands.Type "exit" toleave the HBase ShellVersion 1.1.2.2.4.3.0-227, rUnknown, FriSep 9 23:34:30 UTC 2016 hbase (main): 001 >
Enter help to view help information
Hbase (main): 001version 0 > helpHBase Shell, version 1.1.2.2.4.3.0-227 version r unknown, Fri Sep 9 23:34:30 UTC 2016Type 'help "COMMAND", (e.g.'help "get"'-- the quotes are necessary) for help on a specificcommand.Commands are grouped. Type 'help "COMMAND_GROUP", (e.g.' help "general"') for help on acommand group. COMMAND GROUPS: Group name: general Commands: status, table_help, version, whoami...
View server status:
Hbase (main): 002backup masters 0 > status1 active master, 0 backup masters, 4servers, 0 dead, 20.5000 average load
View version information
Hbase (main): 003version1.1.2.2.4.3.0 0 > version1.1.2.2.4.3.0-227, rUnknown, Fri Sep 9 23:34:30 UTC 2016
View the current user:
Hbase (main): 004auth:SIMPLE 0 > whoamiroot (auth:SIMPLE) groups: root
View help information for table-related commands:
Hbase (main): 005 0 > table_helpHelp for table-reference commands. You can either create a table via 'create'and then manipulate the table via commands like' put', 'get', etc.See the standard help information for howto use each of these commands.
Create a tabl
Common syntax: create'[namespacename:] tablename' [, 'columnfamilyname1' [,' columnfamilyname2,....]]
Use help-create to view create statements for detailed syntax
Hbase (main): 006 in 0 > create 'test','fam1','fam2'0 row (s) in 8.3530 seconds = > Hbase::Table-test
Use the list command to list the table names:
Common syntax: list'[namespacename:] tablename]
The detailed syntax can be viewed using help 'list'. List can be followed by a regular expression to list the table names that match the expression.
Hbase (main): 011test' 0 > list 'test'-lists the table name TABLE test named test 1 row (s) in 0.0110 seconds = > ["test"] hbase (main): 012test 0 > list 'tes.*'- lists the table name TABLE starting with the name TABLE Test Test:testtable 2 row (s) in 0.0150 seconds = > ["test" "test:testtable"] hbase (main): 013main 0 > list 'default:.*'-lists the table name TABLE ambarismoketest under the default namespace Test 2 row (s) in 0.0150 seconds = > ["ambarismoketest" "test"] hbase (main): 014list 0 > list 'test:.*'-lists the table name TABLE test:testtable under the namespace test 1 row (s) in 0.0140 seconds = > ["test:testtable"]
Use the desc command to view the specific information of the specified table (desc is equivalent to describe)
Syntax: desc'[namespacename:] tablename'
Describe'[namespacename:] tablename'
Use help 'describe' to view detailed syntax
Hbase (main): 016 test 0 > desc 'test' View the information in this table Table test is ENABLED test COLUMN FAMILIES DESCRIPTION {NAME = > 'fam1' BLOOMFILTER = > 'ROW', VERSIONS = >' 1century, IN_MEMORY = > 'false', KEEP_DELETED_CELLS = >' FALSE', DATA_BLOCK_ENCODING = > 'NONE', TTL = >' FOREVER', COMPRESSION = > 'NONE', MIN_VERSIONS = >' 01' true', BLOCKSIZE = > '65536', REPLICATION_SCOPE = >' 0'} {NAME = > 'fam2', BLOOMFILTER = >' ROW', VERSIONS = >'1'' IN_MEMORY = > 'false', KEEP_DELETED_CELLS = >' FALSE', DATA_BLOCK_ENCODING = > 'NONE', TTL = >' FOREVER', COMPRESSION = > 'NONE', MIN_VERSIONS = >' 0prima BLOCKCACHE = > 'true', BLOCKSIZE = >' 65536' REPLICATION_SCOPE = >'0'} 2 row (s) in 0.1710 seconds hbase (main): 017seconds hbase 0 > desc 'test:testtable' View the information of the testtable table under the test namespace Table test:testtable is ENABLED Test:testtable COLUMN FAMILIES DESCRIPTION {NAME = > 'colfam1' BLOOMFILTER = > 'ROW', VERSIONS = >' 1century, IN_MEMORY = > 'false', KEEP_DELETED_CELLS = >' FALSE', DATA_BLOCK_ENCODING = > 'NONE', TTL = >' FOREVER', COMPRESSION = > 'NONE', MIN_VERSIONS = >' 0', BLOCKCACHE = > 'true', BLOCKSIZE = >' 65536', REPLICATION_SCOPE = >'0'} {NAME = > 'colfam2', BLOOMFILTER = >' ROW', VERSIONS = >'1'' IN_MEMORY = > 'false', KEEP_DELETED_CELLS = >' FALSE', DATA_BLOCK_ENCODING = > 'NONE', TTL = >' FOREVER', COMPRESSION = > 'NONE', MIN_VERSIONS = >' 013', BLOCKCACHE = > 'true', BLOCKSIZE = >' 65536', REPLICATION_SCOPE = >'0'} {NAME = > 'colfam3', BLOOMFILTER = >' ROW', VERSIONS = >'1', IN_MEMORY = > 'false', KEEP_DELETED_CELLS = >' FALSE' DATA_BLOCK_ENCODING = > 'NONE', TTL = >' FOREVER', COMPRESSION = > 'NONE', MIN_VERSIONS = >' 013', BLOCKCACHE = > 'true', BLOCKSIZE = >' 65536', REPLICATION_SCOPE = >'0'} 3 row (s) in 0.0290 seconds
Insert data using put
Common syntax: put'[namespacename:] tablename', 'rowkey',' columnfamilyname [: column]', 'value'
Use help 'put' to view detailed syntax
Hbase (main): 002secondshbase 0 > put'test','row2','fam1:a','value'0 row (s) in 0.3760 secondshbase (main): 003secondshbase 0 > put'test',' row1','fam1:a','value'0 row (s) in 0.3760 secondshbase (main): 004in 0 > put'test',' row1','fam2:a','value'0 row (s) in 0.3760 secondshbase (main): 005in 0 > put'test','row2','fam2:a' 'value'0 row (s) in 0.3760 seconds
Use scan to view full table data
Common syntax: scan'[namespacename:] tablename'
Use help 'scan' to view detailed syntax
Hbase (main): 002 scan 0 > test'ROW COLUMN+CELL row1 column=fam1:a, timestamp=1504767451331 Value=value row1 column=fam2:a, timestamp=1504767471977, value=value row2 column=fam1:a, timestamp=1504767600686 Value=value row2 column=fam2:a, timestamp=1504767715014, value=value 2 row (s) in 0.1120 seconds
View the data for the specified column:
Hbase (main): 004test', 0 > scan 'test', {COLUMNS= >' fam1:a'} ROW COLUMN+CELL row1 column=fam1:a, timestamp=1504767451331 Value=value row2 column=fam1:a,timestamp=1504767600686, value=value 2 row (s) in 0.2390 seconds hbase (main): 021 seconds hbase 0 > get 'test' 'row1'COLUMN CELL fam1:a timestamp=1504768075731 Value=\ X00\ x00\ x02 fam2:a timestamp=1504767471977, value=value 2 row (s) in 0.1110 seconds
Use get to query data:
Syntax: get'[namespacename:] tablename', 'rowkey' [,' columnfamliyname [: column]]
Use help 'get' to view detailed syntax
Hbase (main): 024pur0 > get'test','row1','fam1'COLUMN CELL fam1:a timestamp=1504768075731 Value=\ X00\ x00\ x02 1 row (s) in 0.0690 secondshbase (main): 026secondshbase 0 > get 'test','row1' 'fam1:a'COLUMN CELL fam1:a timestamp=1504768075731 Value=\ X00\ x00\ x02 1 row (s) in 0.0430 seconds
Delete data using delete
Common syntax: delete'[namespacename:] tablename', 'rowkey',' columnfamliyname:column'
When there is data in the table that only defines columnfamily but not column, delete can use this.
Delete'[namespacename:] tablename', 'rowkey',' columnfamliyname', does not have such data, and using such a statement will not delete the data.
More detailed syntax is viewed using help 'delete'
Hbase (main): 008 0 > delete'test','row1' 'fam1:a'0 row (s) in 0.3370 seconds hbase (main): 009 seconds hbase 0 > scan' test'ROW COLUMN+CELL row1 column=fam2:a, timestamp=1504767471977 Value=value row2 column=fam1:a, timestamp=1504767600686, value=value row2 column=fam2:a, timestamp=1504767715014 Value=value 2 row (s) in 0.0850 seconds
Use incr to increase data (default uses counter to achieve increment)
Common syntax: incr'[namespacename:] tablename', 'rowkey',' columnfamilyname:column'
More detailed syntax is viewed using help 'incr'
Hbase (main): 012 0 > incr'test','row1' 'fam1:a'COUNTER VALUE = 10 row (s) in 1.1700 seconds hbase (main): 013 in 0 > scan' test'ROW COLUMN+CELL row1 column=fam1:a,timestamp=1504768054892 Value=\ X00\ X01 row1 column=fam2:a, timestamp=1504767471977, value=value row2 column=fam1:a, timestamp=1504767600686 Value=value row2 column=fam2:a, timestamp=1504767715014,value=value 2 row (s) in 0.0410 seconds hbase (main): 014 row 0 > incr'test','row1' 'fam1:a'COUNTER VALUE = 20 row (s) in 0.0480 seconds hbase (main): 015 seconds hbase 0 > scan' test'ROW COLUMN+CELL row1 column=fam1:a, timestamp=1504768075731 Value=\ X00\ x00\ x02 row1 column=fam2:a, timestamp=1504767471977, value=value row2 column=fam1:a, timestamp=1504767600686 Value=value row2 column=fam2:a, timestamp=1504767715014, value=value 2 row (s) in 0.0770 seconds
Use get_counter to view the current countermeasure:
Hbase (main): 027 0 > get_counter'test','row1','fam1:a'COUNTER VALUE = 2
Use put to update the data:
Hbase (main): 029 scan 0 > test'ROW COLUMN+CELL row1 column=fam1:a, timestamp=1504768075731 Value=\ X00\ x00\ x02 row1 column=fam2:a, timestamp=1504767471977, value=value row2 column=fam1:a, timestamp=1504767600686 Value=value row2 column=fam2:a, timestamp=1504767715014, value=value 2 row (s) in 0.0270 seconds hbase (main): 030 value=value 0 > put'test','row1','fam1:a' 'newvalue'0 row (s) in 0.0250 seconds hbase (main): 031 seconds hbase 0 > scan 'test'ROW COLUMN+CELL row1 column=fam1:a, timestamp=1504768397480 Value=newvalue row1 column=fam2:a, timestamp=1504767471977, value=value row2 column=fam1:a, timestamp=1504767600686 Value=value row2 column=fam2:a, timestamp=1504767715014, value=value 2 row (s) in 0.0760 seconds
Use is_enabled/is_disabled to see if the table is enabled / disabled
Hbase (main): 032 test'true 0 > is_enable' test'NoMethodError: undefined method `is_enable' test'NoMethodError # hbase (main): 033 0 > is_enabled'0 row (s) in 0.1180 seconds hbase (main): 034 test'false 0 > is_disabled 'test'false 0 row (s) in 0.0190 seconds
Disable tables using disable
Hbase (main): 001test'0 row (s) in 4.7170 seconds hbase (main): 002test'0 row 0 > is_disabled 'test'true 0 row (s) in 0.0210 seconds
Use the enbale enabler table
Hbase (main): 003row 0 > enable 'test'0 row (s) in 2.2910 seconds hbase (main): 004test'0 row 0 > is_enabled 'test'true 0 row (s) in 0.0180 seconds
Delete the columnfamily of fam1:
Hbase (main): 007 NAME= 0 > alter'test', {NAME= > 'fam1' METHOD= > 'delete'} Updating all regions with the new schema...1/1 regions updated.Done.0 row (s) in 2.1980 seconds hbase (main): 008Updating all regions with the new schema...1/1 regions updated.Done.0 row 0 > desc' test'Table test is ENABLED test COLUMN FAMILIES DESCRIPTION {NAME = > 'fam2' BLOOMFILTER = > 'ROW',VERSIONS = >' 1century, IN_MEMORY = > 'false', KEEP_DELETED_CELLS = >' FALSE',DATA_BLOCK_ENCODING = > 'NONE', TTL = >' FOREVER', COMPRESSION = > 'NONE', MIN_VERSIONS = >' 0,0,0001 row (s) in 0.0350 seconds = > 'true', BLOCKSIZE = >' 65536mm, REPLICATION_SCOPE = >'0'} 1 row (s)
Clear the table data:
Hbase (main): 009 test'Truncating 0 > truncate 'test'Truncating' test' table (it may take awhile):-Disabling table... -Truncating table...0 row (s) in 3.6540 seconds hbase (main): 010 scan 0 > scan'te