HBase Shell Commands in Practice 1


In Our previous posts we have seen HBase Overview and HBase Installation, now it is the time to practice some Hbase Shell Commands to get familiarize with HBase. We will test a few Hbase shell commands in this post.

HBase Shell Usage

  • Quote all names in HBase Shell such as table and column names.
  • Commas delimit command parameters.
  • Type <RETURN> after entering a command to run it.
  • Dictionaries of configuration used in the creation and alteration of tables are Ruby Hashes. They look like this:

{‘key1’ => ‘value1’, ‘key2’ => ‘value2’, …}

and are opened and closed with curley-braces.

  • Key/values are delimited by the ‘=>’ character combination.
  • Usually keys are predefined constants such as NAME, VERSIONS, COMPRESSION, etc.
  • Constants do not need to be quoted. Type ‘Object.constants’ to see a (messy) list of all constants in the environment.
  • If you are using binary keys or values and need to enter them in the shell, use double-quote’d hexadecimal representation. For example:

The HBase shell is the (J)Ruby IRB with the below HBase-specific commands added.

HBase Shell Commands

HBase Shell Commands can be categorized into below types.

  • HBase Shell General Commands
  • Data Definition Commands
  • Data Manipulation Commands
  • Other HBase Shell Commands

General Commands

  • status – shows the cluster status
  • table_help – help on Table reference commands, scan, put, get, disable, drop etc.
  • version – displays HBase version
  • whoami – shows the current HBase user.

DDL Commands

alter

add/modify/delete column families, as well as change table configuration

Add/Change column family

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:

we can operate on several column families:

Delete column family

To delete the ‘f1’ column family in table ‘ns1:t1’, use one of:

Alter Table Properties

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

alter_async

Same as alter command but does not wait for all regions to receive the schema changes.

alter_status

Gets the status of the alter command. Indicates the number of regions of the table that have received the updated schema. Examples are

create

Used for Creating tables. Pass a table name, and a set of column family specifications (at least one), and, optionally, table configuration as arguments.

Examples:

1. Create a table with namespace=ns1 and table qualifier/name=t1

2. Create a table with namespace=default and table qualifier=t1