HBase Create Table - HBase

How to create a table in HBase?

Creating a Table using HBase Shell

Table can be created using create command by specifying the table name and the Column Family name. Syntax for creating a table in HBase shell is shown below.

Example

Below is a sample schema of a table named emp which has two column families: “personal data” and “professional data”.

Row key

personal data

professional data

This table can be created in HBase shell as shown below.

This will give you below output.

Verification

User can verify if the table is created using the list command as shown below. Here you can observe the created emp table.

Creating a Table Using java API

A table in HBase can be created using createTable() method of HBaseAdmin class. This class belongs to org.apache.hadoop.hbase.client package. Below are the steps for creating a table in HBase using java API.

Step1: Instantiate HBaseAdmin

This class requires the Configuration object as a parameter, therefore initially instantiate the Configuration class and pass this instance to HBaseAdmin.

Step2: Create TableDescriptor

HTableDescriptor is a class which belongs to the org.apache.hadoop.hbase class. This c

Step 3: Execute through Admin

Created table can be executed in Admin mode Using createTable() method of HBaseAdmin class.

Below is the complete program for creating a table via admin.

Compile and execute the above program as shown below.

Output:

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

HBase Topics