Home > Hbase > Hbase Shell

Hbase Shell

# Useful commands:help ‘command’, status, list, describe ‘<tablename>’

The status command shows basic status about the cluster, such as whether there are dead nodes. status ‘simple’ and status ‘detailed’ show additional information.

# CREATE TABLES
hbase> create ‘t1’, {NAME => ‘fam1’}, {NAME => ‘fam2’}
hbase> create ‘t1’, ‘fam1’, ‘fam2’ # Shorthand

# SCAN
To scan the rows of a table, use scan ‘tablename’. There are several options that can be used to restrict what data is returned: COLUMNS: To retrieve only certain columns.For all the columns in a column family, leave the qualifier empty (e.g., ‘fam1:’). START ROW/STOP ROW: The row key to start or stop scanning from. TIMESTAMP: A specific timestamp to search for (this is a long type).
LIMIT: The number of row keys to return.

# COUNT
hbase> count ‘tablename’, 5000
To count the rows of a table, and report results every 5000 rows. This can be very slow for large tables.

# DELETE
The delete command can be used to delete certain columns.In order to delete an entire row including all of its columns, use delete all.To delete all the rows from a table, use truncate ‘tablename’. Under the hood, HBase will disable, drop, and re-create the table

* delete column in a row:
hbase> delete ”, ‘rowkey’, ‘col’
hbase> delete ‘t1’, ‘r1’, ‘fam1:c1’
* delete an entire row
hbase> delete ”, ‘rowkey’
hbase> delete ‘t1’, ‘r1’
* delete all the rows
hbase> truncate ‘<tablename>’

# REMOVE TABLE
To remove a table completely, use the dropcommand. However, a table cannot be dropped unless it is first disabled:
hbase> disable ‘<tablename>’hbase> drop ”
If the table hadmore than 1 Region, it is recommended to compact the META table:
hbase> major_compact’.META.’

# CHANGE COLUMN FAMILY
To change or add column families,the table must be disabled: disable ‘tablename’. While a table is disabled, clients will not be able to access the table. After the alteration, re-enable the table with the command enable ‘tablename’.
To add or change column families, the alter command uses the same syntax. The only difference is whether that column family name already exists or not.
To remove column families, this option must be included: METHOD => ‘delete’

* must disable table first
* Add or change column families
hbase> alter ‘<tablename>’, {NAME => ‘<colfam>’ [,<options>]}

* Remove column families
hbase> alter ‘<tablename>’, {NAME => ‘<colfam>’, METHOD =>’delete’}

# HBASE and HDFS

* Store files are stored as HFiles in HDFS

– sorted key/value pairs and an index of keys

– /hbase/tablename/region/column-family

 

 

Advertisements
Categories: Hbase
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: