Hbase Namespace Commands and Examples

  • Post author:
  • Post last modified:February 27, 2018
  • Post category:BigData
  • Reading time:4 mins read

You can compare the namespace to the RDBMS shema’s. You can create the namespace in the HBase table and then create multiple tables in that namespace. In this article, we will check out Hbase namespace commands with an examples.

Hbase Namespace Commands

Hbase Namespace Commands

There are three commonly used namespace commands: create_namespace, alter_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables

HBase create_namesace command

This command is used to create a namespace in the HBase. Below are the examples to create namespace:

hbase(main):019:0> create 'test:test1','cf'
0 row(s) in 2.3760 seconds
=> Hbase::Table - test:test1

Create Table inside HBase Namespace

Once namespace is created, you can create the tables inside that namespace. Just like any other RDBMS schema, you have to append the namespace name with table name.

By default tables will be created in HBase ‘default’ namespace.

Below example demonstrates creating table ‘test1’ in namespace ‘test’:

hbase(main):019:0> create ‘test:test1’,’cf’0 row(s) in 2.3760 seconds=> Hbase::Table – test:test1

Verify the table presence in namespace ‘test’ with list command.

hbase(main):020:0> list 'test:test1'
TABLE
test:test1
1 row(s) in 0.0050 seconds
=> ["test:test1"]

HBase alter_namespace command

This command is used to alter already created namespace in the HBase. Below is the example to alter namespace in HBase:

hbase(main):046:0> alter_namespace 'test', {METHOD => 'set', 'PROERTY_NAME' => 'PROPERTY_VALUE'}
0 row(s) in 0.1230 seconds

HBase describe_namespace Command

Describe_namespace command is used to describe the HBase namespaces. Below is the example to describe the HBase namespace.

hbase(main):047:0> describe_namespace 'test'
DESCRIPTION
{NAME => 'test', PROERTY_NAME => 'PROPERTY_VALUE'}
1 row(s) in 0.0050 seconds

HBase list_namespace Command

The list_namespace command is used to list or display all available namespaces in the HBase.

Below is the example to display all the namespaces available in HBase:

hbase(main):048:0> list_namespace
NAMESPACE
default
hbase
my_ns
test
4 row(s) in 0.0620 seconds

HBase list_namespace_tables Command

The list_namespace_tables command is used to list or display the tables available in given namespace. Below example display the tables available in ‘test’ namespace.

hbase(main):050:0> list_namespace_tables 'test'
TABLE
test1
1 row(s) in 0.0550 seconds

HBase drop_namespace Command

This command is used to drop the named namespace present in the table. You can drop only empty namespace. You must drop all the tables created in that namespace before attempting to drop it.

Below is the example to drop namespace:

hbase(main):044:0> drop_namespace 'test'
0 row(s) in 0.0540 seconds

Read:

 

This Post Has 2 Comments

  1. hema

    how to insert data to table which are in different namespace…i mean how to change namespace from default to another namespace

    i have namespace like ‘test:test1’. i want to insert data to test1.how to do this ??

    1. Vithal Sampagar

      Hi,

      There is no straight forward way to copy tables from one namespace to other. You have to create snapshot of tables that you are moving.
      You can read more on Hbase official document – HBase Snapshot

      Edit: If you are trying to insert individual value then you can do that with help of ‘put’ command. Below is example for your reference:

      hbase(main):005:0> put 'test:personal',1,'personal_data:name','Ram'
      0 row(s) in 0.2130 seconds

      hbase(main):006:0> put 'test:personal',1,'personal_data:city','Bengaluru'
      0 row(s) in 0.0140 seconds

      hbase(main):007:0> put 'test:personal',1,'personal_data:age','25'
      0 row(s) in 0.0080 seconds

      hbase(main):008:0> scan 'test:personal'
      ROW COLUMN+CELL
      1 column=personal_data:age, timestamp=1517380744352, value=25
      1 column=personal_data:city, timestamp=1517380737729, value=Bengaluru
      1 column=personal_data:name, timestamp=1517380688917, value=Ram
      1 row(s) in 0.0320 seconds

      Thanks

Comments are closed.