Describe and Alter a Table

Describe

This command returns the description of the table. Its syntax is as follows

hbase> describe 'table name'

Given below is the output of the describe command on the emp table.

hbase> describe 'emp'
   DESCRIPTION      ENABLED
      
'emp', {NAME ⇒ 'READONLY', DATA_BLOCK_ENCODING ⇒ 'NONE', BLOOMFILTER
⇒ 'ROW', REPLICATION_SCOPE ⇒ '0', COMPRESSION ⇒ 'NONE', VERSIONS ⇒
'1', TTL true

⇒ 'FOREVER', MIN_VERSIONS ⇒ '0', KEEP_DELETED_CELLS ⇒ 'false',
BLOCKSIZE ⇒ '65536', IN_MEMORY ⇒ 'false', BLOCKCACHE ⇒ 'true'}, {NAME
⇒ 'personal

data', DATA_BLOCK_ENCODING ⇒ 'NONE', BLOOMFILTER ⇒ 'ROW',
REPLICATION_SCOPE ⇒ '0', VERSIONS ⇒ '5', COMPRESSION ⇒ 'NONE',
MIN_VERSIONS ⇒ '0', TTL

⇒ 'FOREVER', KEEP_DELETED_CELLS ⇒ 'false', BLOCKSIZE ⇒ '65536',
IN_MEMORY ⇒ 'false', BLOCKCACHE ⇒ 'true'}, {NAME ⇒ 'professional
data', DATA_BLO

CK_ENCODING ⇒ 'NONE', BLOOMFILTER ⇒ 'ROW', REPLICATION_SCOPE ⇒ '0',
VERSIONS ⇒ '1', COMPRESSION ⇒ 'NONE', MIN_VERSIONS ⇒ '0', TTL ⇒
'FOREVER', K

EEP_DELETED_CELLS ⇒ 'false', BLOCKSIZE ⇒ '65536', IN_MEMORY ⇒
'false', BLOCKCACHE ⇒ 'true'}, {NAME ⇒ 'table_att_unset',
DATA_BLOCK_ENCODING ⇒ 'NO 

NE', BLOOMFILTER ⇒ 'ROW', REPLICATION_SCOPE ⇒ '0', COMPRESSION ⇒
'NONE', VERSIONS ⇒ '1', TTL ⇒ 'FOREVER', MIN_VERSIONS ⇒ '0',
KEEP_DELETED_CELLS

⇒ 'false', BLOCKSIZE ⇒ '6
Alter

This command used to make changes to an existing table. Using this command, you can change the maximum number of cells of a column family, set and delete table scope operators, and delete a column family from a table.

Changing the Maximum Number of Cells of a Column Family

Given below is the syntax to change the maximum number of cells of a column family.

hbase> alter 't1', NAME ⇒ 'f1', VERSIONS ⇒ 6

In the following example, the maximum number of cells is set to 6.

hbase> alter 'emp', NAME ⇒ 'personal data', VERSIONS ⇒ 6
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 3.5020 seconds

Table Scope Operators

Using alter, you can set and remove table scope operators such as

  • MAX_FILESIZE
  • READONLY
  • MEMSTORE_FLUSHSIZE
  • DEFERRED_LOG_FLUSH, etc.

Setting Read Only

Below given is the syntax to make a table read only.

hbase>alter 't1', READONLY(option)

In the following example, we have made the emp table read only.

hbase> alter 'emp', READONLY
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 3.1430 seconds

Removing Table Scope Operators

We can also remove the table scope operators. Given below is the syntax to remove ‘MAX_FILESIZE’ from emp table.

hbase> alter 't1', METHOD ? 'table_att_unset', NAME ? 'MAX_FILESIZE'

Deleting a Column Family

Using alter, you can also delete a column family. Given below is the syntax to delete a column family using alter.

hbase> alter ‘ table name ’, ‘delete’ ? ‘ column family ’

Following is an example to delete a column family from the ‘emp’ table. Let us assume there is a table named employee in HBase. It contains the following data

hbase> scan 'employee'

   ROW                   COLUMN+CELL
row1 column = personal:city, timestamp = 1418193767, value = Bhimavaram
row1 column = personal:name, timestamp = 1418193806767, value = Ashok
row1 column = professional:designation, timestamp = 1418193767, value = Software Engineer
row1 column = professional:salary, timestamp = 1418193806767, value = 25000

1 row(s) in 0.0145 seconds

Now let us delete the column family named professional using the alter command.

hbase> alter 'employee','delete'?'professional'
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 2.2380 seconds

Now verify the data in the table after alteration. Observe the column family ‘professional’ is no more, since we have deleted it.

hbase> scan 'employee'
   ROW             COLUMN + CELL
row1 column = personal:city, timestamp = 14181936767, value = Bhimavaram
row1 column = personal:name, timestamp = 1418193806767, value = Ashok

1 row(s) in 0.1120 seconds
Adding a Column Family Using Java API
package com.ashok.hbase;

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.client.HBaseAdmin;

/**
 * 
 * @author ashok.mariyala
 *
 */
public class AddColoumn{

   public static void main(String args[]) throws MasterNotRunningException, IOException{

      // Instantiating configuration class.
      Configuration conf = HBaseConfiguration.create();

      // Instantiating HBaseAdmin class.
      HBaseAdmin admin = new HBaseAdmin(conf);

      // Instantiating columnDescriptor class
      HColumnDescriptor columnDescriptor = new HColumnDescriptor("contactDetails");
     
      // Adding column family
      admin.addColumn("employee", columnDescriptor);
      System.out.println("Coloumn added successfully");
   }
}
Deleting a Column Family Using Java API
package com.ashok.hbase;

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.client.HBaseAdmin;

/**
 * 
 * @author ashok.mariyala
 *
 */
public class DeleteColoumn{

   public static void main(String args[]) throws MasterNotRunningException, IOException{

      // Instantiating configuration class.
      Configuration conf = HBaseConfiguration.create();

      // Instantiating HBaseAdmin class.
      HBaseAdmin admin = new HBaseAdmin(conf);

      // Deleting a column family
      admin.deleteColumn("employee","contactDetails");
      System.out.println("Coloumn deleted successfully"); 
   }
}
Describe and Alter a Table

Scroll to top