Hbase Shell
Hbase Shell
com
Alter The coprocessor attribute must match the pattern below in order for
[email protected] www.datadotz.com
You can also set configuration settings specific to this table or column family:
hbase> alter_async ‘t1′, NAME => ‘f1′, METHOD => ‘delete’or a shorter
version:hbase> alter_async ‘t1′, ‘delete’ => ‘f1′
You can also change table-scope attributes like MAX_FILESIZE
MEMSTORE_FLUSHSIZE, READONLY, and DEFERRED_LOG_FLUSH.
hbase> alter ‘t1′, {NAME => ‘f1′}, {NAME => ‘f2′, METHOD => ‘delete’}
To check if all the regions have been updated, use alter_status <table_name>
alter_async
3) Data Manipulation commands
Count the number of rows in a table. Return value is the number of
rows.
This operation may take a LONG time (Run
‘$HADOOP_HOME/bin/hadoop jar
hbase.jar rowcount’ to run a counting mapreduce job). Current
count is shown
every 1000 rows by default. Count interval may be optionally
specified. Scan
Count caching is enabled on count scans by default. Default cache size is
[email protected] www.datadotz.com
10 rows.
If your rows are small in size, you may want to increase this
parameter. Examples:hbase> count ‘t1′
hbase> count ‘t1′, INTERVAL => 100000
hbase> count ‘t1′, CACHE => 1000
hbase> count ‘t1′, INTERVAL => 10, CACHE => 1000
The same commands also can be run on a table reference.
Suppose you had a reference
t to table ‘t1′, the corresponding commands would be:hbase>
t.count
hbase> t.count INTERVAL => 100000
hbase> t.count CACHE => 1000
hbase> t.count INTERVAL => 10, CACHE => 1000
Put a delete cell value at specified table/row/column and optionally
timestamp coordinates. Deletes must match the deleted cell’s
coordinates exactly. When scanning, a delete cell suppresses
older
versions. To delete a cell from ‘t1′ at row ‘r1′ under column ‘c1′
marked with the time ‘ts1′, do:
hbase> delete ‘t1′, ‘r1′, ‘c1′, ts1
The same command can also be run on a table reference.
Suppose you had a reference
t to table ‘t1′, the corresponding command would be:hbase>
Delete t.delete ‘r1′, ‘c1′, ts1
Delete all cells in a given row; pass a table name, row, and
optionally
a column and timestamp. Examples:hbase> deleteall ‘t1′, ‘r1′
hbase> deleteall ‘t1′, ‘r1′, ‘c1′
hbase> deleteall ‘t1′, ‘r1′, ‘c1′, ts1
The same commands also can be run on a table reference.
Suppose you had a reference
t to table ‘t1′, the corresponding command would be:hbase>
t.deleteall ‘r1′
hbase> t.deleteall ‘r1′, ‘c1′
Deleteall hbase> t.deleteall ‘r1′, ‘c1′, ts1
Get row or cell contents; pass table name, row, and optionally
a dictionary of column(s), timestamp, timerange and versions.
Examples:
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}
Get hbase> get ‘t1′, ‘r1′, {FILTER => “ValueFilter(=, ‘binary:abc’)”}
[email protected] www.datadotz.com
tell the region servers to unassign all the regions to balance (the re-assignment itself is
async).
Otherwise false (Will not run if regions in transition).
Examples:
hbase> balancer
Enable/Disable balancer. Returns previous balancer state.
Examples:
hbase> balance_switch true
balance_switch hbase> balance_switch false
Close a single region. Ask the master to close a region out on the cluster
or if ‘SERVER_NAME’ is supplied, ask the designated hosting regionserver to
close the region directly. Closing a region, the master expects ‘REGIONNAME’
to be a fully qualified region name. When asking the hosting regionserver to
directly close a region, you pass the regions’ encoded name only. A region
name looks like
this:TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.The
trailing period is part of the regionserver name. A region’s encoded name
is the hash at the end of a region name; e.g. 527db22f95c8a9e0116f0cc13c680396
(without the period). A ‘SERVER_NAME’ is its host, port plus startcode. For
example: host187.example.com,60020,1289493121758 (find servername in master ui
or when you do detailed status in shell). This command will end up running
close on the region hosting regionserver. The close is done without the
master’s involvement (It will not know of the close). Once closed, region will
stay closed. Use assign to reopen/reassign. Use unassign or move to assign
the region elsewhere on cluster. Use with caution. For experts only.
Examples:hbase> close_region ‘REGIONNAME’
close_region hbase> close_region ‘REGIONNAME’, ‘SERVER_NAME’
Compact all regions in passed table or pass a region row
to compact an individual region. You can also compact a single column
family within a region.
Examples:
Compact all regions in a table:
hbase> compact ‘t1′
Compact an entire region:
hbase> compact ‘r1′
Compact only a column family within a region:
hbase> compact ‘r1′, ‘c1′
Compact a column family within a table:
Compact hbase> compact ‘t1′, ‘c1′
Flush all regions in passed table or pass a region row to
flush an individual region. For example:hbase> flush ‘TABLENAME’
flush hbase> flush ‘REGIONNAME’
Run major compaction on passed table or pass a region row
to major compact an individual region. To compact a single
column family within a region specify the region name
major_compact followed by the column family name.
[email protected] www.datadotz.com
Examples:
Compact all regions in a table:
hbase> major_compact ‘t1′
Compact an entire region:
hbase> major_compact ‘r1′
Compact a single column family within a region:
hbase> major_compact ‘r1′, ‘c1′
Compact a single column family within a table:
hbase> major_compact ‘t1′, ‘c1′
Move a region. Optionally specify target regionserver else we choose one
at random. NOTE: You pass the encoded region name, not the region name so
this command is a little different to the others. The encoded region name
is the hash suffix on region names: e.g. if the region name were
TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396. then
the encoded region name portion is 527db22f95c8a9e0116f0cc13c680396
A server name is its host, port plus startcode. For example:
host187.example.com,60020,1289493121758
Examples:hbase> move ‘ENCODED_REGIONNAME’
move hbase> move ‘ENCODED_REGIONNAME’, ‘SERVER_NAME’
Split entire table or pass a region to split individual region. With the
second parameter, you can specify an explicit split key for the region.
Examples:
split ‘tableName’
split ‘regionName’ # format: ‘tableName,startKey,id’
split ‘tableName’, ‘splitKey’
split split ‘regionName’, ‘splitKey’
Unassign a region. Unassign will close region in current location and then
reopen it again. Pass ‘true’ to force the unassignment (‘force’ will clear
all in-memory state in master before the reassign. If results in
double assignment use hbck -fix to resolve. To be used by experts).
Use with caution. For expert use only. Examples:hbase> unassign ‘REGIONNAME’
unassign hbase> unassign ‘REGIONNAME’, true
Roll the log writer. That is, start writing log messages to a new file.
The name of the regionserver should be given as the parameter. A
‘server_name’ is the host, port plus startcode of a regionserver. For
example: host187.example.com,60020,1289493121758 (find servername in
master ui or when you do detailed status in shell)
hlog_roll hbase>hlog_roll
Dump status of HBase cluster as seen by ZooKeeper. Example:
zk_dump hbase>zk_dump