Hbase Shell Commands

Our HadoopTpoint App is now available in google play store,please rate and comment it in play store : W3Schools

Hbase Shell Commands

 

HBase shell commands are mainly categorized into 6 parts

1) General Hbase Shell commands

Show cluster status. Can be ‘summary’, ‘simple’, or ‘detailed’. Thedefault is ‘summary’.

 

2) Tables Management commands

Alter column family schema; pass table name and a dictionary specifying new column family schema. Dictionaries are described on the main help command output.Dictionary must include name of column family to alter.For example, to change or add the ‘f1′ column family in table ‘t1′ from current value to keep a maximum of 5 cell VERSIONS, do:

 

alter
You can also change table-scope attributes like MAX_FILESIZE, READONLY,MEMSTORE_FLUSHSIZE,DEFERRED_LOG_FLUSH, etc. These can be put at the end;
for example, to change the max size of a region to 128MB, do:

 

Since you can have multiple coprocessors configured for a table, a sequence number will be automatically appended to the attribute name to uniquely identify it. The coprocessor attribute must match the pattern below in order for the framework to understand how to load the coprocessor classes:

[coprocessor jar file location] | class name | [priority] | [arguments]
You can also set configuration settings specific to this table or column family:

 

You can also remove a table-scope attribute:

 

There could be more than one alteration in one command:

 

Create table; pass table name, a dictionary of specifications per column family, and optionally a dictionary of table configuration.
create

 

# The above in shorthand would be the following:

 

Table configuration options can be put at the end.
describe Describe the named table.

 

disable Start disable of named table

 

disable_all Disable all of tables matching the given regex

 

is_disabled verifies Is named table disabled

 

drop Drop the named table. Table must first be disabled

 

drop_all Drop all of the tables matching the given regex

 

enable Start enable of named table

 

enable_all
Enable all of the tables matching the given regex

 

is_enabled verifies Is named table enabled

 

exists Does the named table exist

 

list
show_filters
alter_status
alter_async
List all tables in hbase. Optional regular expression parameter could
be used to filter the output

 

Show all the filters in hbase.

 

Get the status of the alter command. Indicates the number of regions of the table that have received the updated schema Pass table name.

 

Alter column family schema, does not wait for all regions to receive the schema changes. Pass table name and a dictionary specifying new column family schema. Dictionaries are described on the main help command output. Dictionary must include name of column family to alter. To change or add the ‘f1′ column family in table ‘t1′
from defaults to instead keep a maximum of 5 cell VERSIONS, do:

 

You can also change table-scope attributes like MAX_FILESIZE MEMSTORE_FLUSHSIZE, READONLY, and DEFERRED_LOG_FLUSH.
For example, to change the max size of a family to 128MB, do:

 

To check if all the regions have been updated, use alter_status <table_name>

3) Data Manipulation commands

count
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 caching is enabled on
count scans by default. Default cache size is 10 rows. If your rows are small in size, you may want to increase this parameter. Examples:hbase> count ‘t1′

 

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:

 

delete
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:

 

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> t.delete ‘r1′, ‘c1′, ts1 Delete all cells in a given row; pass a table name, row, and optionally a column and timestamp. Examples:

 

deleteall
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:

 

get
Get row or cell contents; pass table name, row, and optionally a dictionary of column(s), timestamp, timerange and versions. Examples:

 

 

Besides the default ‘toStringBinary’ format, ‘get’ also supports custom formatting by column. A user can define a FORMATTER by adding it to the column name in the get specification. The FORMATTER can be stipulated:1. either as a org.apache.hadoop.hbase.util.Bytes method name (e.g, toInt, toString) 2. or as a custom class followed by method name:

e.g.
‘c(MyFormatterClass).format’.Example formatting cf:qualifier1 and cf:qualifier2 both as Integers:

 

Note that you can specify a FORMATTER by column only (cf:qualifer). You cannot specify a FORMATTER for all columns of a column family.The same commands also can be run on a reference to a table (obtained via get_table or create_table). Suppose you had a reference t to table ‘t1′, the corresponding commands would be:

 

get_counter
Return a counter cell value at specified table/row/column coordinates. A cell cell should be managed with atomic increment function oh HBase and the data should be binary encoded. Example:

 

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:

 

incr
Increments a cell ‘value’ at specified table/row/column coordinates. To increment a cell value in table ‘t1′ at row ‘r1′ under column ‘c1′ by 1 (can be omitted) or 10 do:

 

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.incr ‘r1′, ‘c1′

 

put
Put a cell ‘value’ at specified table/row/column and optionally timestamp coordinates. To put a cell value into table ‘t1′ at row ‘r1′ under column ‘c1′ marked with the time ‘ts1′, do:

 

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:

 

scan
Scan a table; pass table name and optionally a dictionary of scanner specifications. Scanner specifications may include one or more of: TIMERANGE, FILTER, LIMIT, STARTROW, STOPROW, TIMESTAMP, MAXLENGTH, or COLUMNS, CACHEIf no columns are specified, all columns will be scanned. To scan all members of a column family, leave the qualifier empty as in ‘col_family:’.The filter can be specified in two ways:
1. Using a filterString – more information on this is available in the Filter Language document attached to the HBASE-4176 JIRA
2. Using the entire package name of the filter.Some examples:

 

For experts, there is an additional option — CACHE_BLOCKS — which switches block caching for the scanner on (true) or off (false). By default it is enabled. Examples:

 

Also for experts, there is an advanced option — RAW — which instructs the scanner to return all cells (including delete markers and uncollected deleted cells). This option cannot be combined with requesting specific COLUMNS.
Disabled by default. Example:

 

Besides the default ‘toStringBinary’ format, ‘scan’ supports custom formatting by column. A user can define a FORMATTER by adding it to the column name in the scan specification. The FORMATTER can be stipulated:
1. either as a org.apache.hadoop.hbase.util.Bytes method name (e.g, toInt, toString)
2. or as a custom class followed by method name: e.g. ‘c(MyFormatterClass).format’.
Example formatting cf:qualifier1 and cf:qualifier2 both as Integers:

 

Note that you can specify a FORMATTER by column only (cf:qualifer). You cannot specify a FORMATTER for all columns of a column family.
Scan can also be used directly from a table, by first getting a reference to a table, like such:

 

Note in the above situation, you can still provide all the filtering, columns, options, etc as described above.
truncate
Disables, drops and recreates the specified table.
Examples:

 

4)HBase Surgery tools

assign

Assign a region. Use with caution. If region already assigned, this command will do a force reassign. For experts only. Examples:

 

balancer Trigger the cluster balancer. Returns true if balancer ran and was able to 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:

 

Enable/Disable balancer. Returns previous balancer state. Examples:

 

close_region
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 regionnamelookslikethis: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’

 

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:

 

flush
Flush all regions in passed table or pass a region row to flush an individual region. For
example:

 

major_compact 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 followed by the column family name. Examples:
Compact all regions in a table:

 

move
split
unassign
hlog_roll
zk_dump
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:

 

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:

 

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:

 

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)

 

Dump status of HBase cluster as seen by ZooKeeper. Example:

 

5) Cluster replication tools

add_peer
Add a peer cluster to replicate to, the id must be a short and the cluster key is composed like this:
hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent
This gives a full path for HBase to connect to another cluster.
Examples:

[/codesyntax]
remove_peer
list_peers
enable_peer
disable_peer
Stops the specified replication stream and deletes all the meta information kept about it. Examples:

 

 

Restarts the replication to the specified peer cluster,continuing from where it was disabled.Examples:

 

Stops the replication stream to the specified cluster, but still keeps track of new edits to replicate.Examples:

 

Restarts all the replication features. The state in which each stream starts in is undetermined.
start_replication
WARNING: start/stop replication is only meant to be used in critical load situations.
Examples:

 

Stops all the replication features. The state in which each stream stops in is undetermined.
stop_replication
WARNING: start/stop replication is only meant to be used in critical load situations.
Examples:

 

6) Security tools

grant
revoke
Grant users specific rights.
Syntax : grantpermissions is either zero or more letters from the set “RWXCA”.READ(‘R’), WRITE(‘W’), EXEC(‘X’), CREATE(‘C’), ADMIN(‘A’)For example:

 

Revoke a user’s access rights.
Syntax : revoke
For example:


Show all permissions for the particular user.
user_permission Syntax : user_permission
For example:

 

hbase Shell Commands to create table:

Hbase Shell Commands.Here below commands for create ‘airline’ table and also create column family and column qualifier and also insert values

here we are craeting two rows only

 

table name                                    airline

column family 

flightinfo                     column qualifier—flightno,airlines

 flightbetween          column qualifier —- source , destination

  time                           column qualifier-—arrival time,depature time,date

row key  —- row1 and row2

 

Hbase command for retrieve specify columns and row

 

Hbase command for to retrieve entire table

 

Hbase command for count no of rows in table and describe a table

Comments

  1. Nice post about hbase shell commands

Speak Your Mind

*