You are reading the article Hbase Create Table With Java Api &Amp; Shell Example updated in October 2023 on the website Cersearch.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested November 2023 Hbase Create Table With Java Api &Amp; Shell Example
In HBase, we can create table operations in two ways:
JAVA API
Shell Command
We will learn to use both to create Tables in HBase:
How to Create Table in HBase with Java APIIn this section, we are going to perform some of the operations using Java coding through Java API.
Through Java API, we can create tables in HBase and also load data into tables using Java coding.
Establishing a connection with HBase through Java API
Using Eclipse for Java coding, debugging and testing
Establishing connection through Java API:
Following are the steps to create tables in HBase through Java API:
Step 1) Create a Java Project in Eclipse
In this step, we are going to create a Java project in Eclipse for HBase connection.
Creation of new project name “HbaseConnection” in eclipse.
For Java related project set up or creation of program
If we observe the screenshot above.
Give project name in this box. In our case, we have the project name “HbaseConnection”
Check this box for default location to be saved. In this /home/hduser/work/HbaseConnection is the path
Check the box for Java environment here. In this JavaSE-1.7 is the Java edition
Choose your option where you want to save file. In our case, we have selected option second “Create a separate folder for sources and class files”
Step 2) Configure the build Path in Eclipse
On Eclipse home page, follow the following steps:
From above screenshot:
Select build path
Select configure build path
In this step, we will add relevant HBase jars into java project as shown in the screenshot.
Important jars to be added chúng tôi hadoop-core-1.1.2.jar
Come to libraries
Press option – Add External Jars
Select required important jars
Press finish button to add these files to ‘src’ of java project under libraries
After adding these jars, it will show under project “src” location. All the Jar files that fall under the project are now ready for usage with Hadoop ecosystem.
Step 3) Establish the HBase Connection
In this step by using HBaseConnection.java, the HBase Connection would be established through Java Coding
Select Run
Select Run as Java Application
This code will establish a connection with HBase through Java API
After Running this code ‘guru99’ table will be created in HBase with two column families named “education” and “projects”. At present, the empty schema is only created in HBase.
From the screenshot above we are performing following functions:
Using HTableDescriptor we can able to create “guru99” table in HBase
Using addFamily method, we are going to add “education” and “projects” as column names to “guru99” table.
The below coding is going to:
Establish a connection with HBase and
Create “guru99” table with two columns
Code Placed under HBaseConnection_Java document
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.HTableDescriptor; Import org.apache.hadoop.hbase.client.HBaseAdmin; public class HBaseConnection { public static void main(String[] args) throws IOException { HBaseConfigurationhc = new HBaseConfiguration(new Configuration()); HTableDescriptorht = new HTableDescriptor("guru99"); ht.addFamily( new HColumnDescriptor("education")); ht.addFamily( new HColumnDescriptor("projects")); System.out.println( "connecting" ); HBaseAdminhba = new HBaseAdmin( hc ); System.out.println( "Creating Table" ); hba.createTable( ht ); System.out.println("Done......"); } }This is required code you have to place in chúng tôi and have to run a Java program.
After running this program, it is going to establish a connection with HBase and in turn, it will create a table with column names.
The table name is “guru99”
Column names are “education” and “projects”
Step 4) Check the Created Table in HBase
We can check whether “guru99” table is created with two columns in HBase or not by using HBase shell mode with “list” command.
The “list” command gives information about all the tables that is created in HBase.
In this screen, we are going to do
Code checking in HBase shell by executing “list” command.
If we run “list” command, it will display the table created in HBase as below. In our case, we can see table “guru99” is created
HBase Create Table with ShellThe Syntax to Create a table in HBase using Shell is:
Example:-
0 rows(s) in 0.312 seconds
The above example explains how to create a table in HBase with the specified name given according to the dictionary or specifications as per column family. In addition to this, we can also pass some table-scope attributes as well into it.
Summary
HBase is a column-oriented NoSQL database for storing a large amount of data on top of Hadoop Ecosystem.
Handling tables in HBase is a very crucial thing because all important functionalities such as Data operations, Data enhancements and Data modeling we can be performed through only tables in HBase.
Tables perform the following functions:
Creation of tables with column names and rows
Inserting values into tables
Retrieving values from tables
You're reading Hbase Create Table With Java Api &Amp; Shell Example
Update the detailed information about Hbase Create Table With Java Api &Amp; Shell Example on the Cersearch.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!