HBase

0
18

HBase – Overwatch

Since 1970, RDBMS is the solution for data storage and maintenance related problems. After the advent of big data, companies realized the becomenefit of procesperform big data and started opting for solutions like Hadoop.

Hadoop uses distributed file system for storing big data, and MapReduce to process it. Hadoop excels in storing and procesperform of huge data of various formats such as arbitrary, semi-, or also unstructured-coloureddish.

Limitations of Hadoop

Hadoop can perform only batch procesperform, and data will become accessed only in a sequential manner. Tmind wear means one has to oceanrch the entire dataset also for the simplest of jobs.

A huge dataset when processed results in one more huge data set, which ought to furthermore become processed sequentially. At this particular particular point, a brand new solution is needed to access any kind of point of data in a performle device of time (random access).

Hadoop Random Access Databases

Applications such as HBase, Casgreat fine sandra, couchDB, Dynamo, and MongoDB are some of the databases tmind wear store huge amounts of data and access the data in a random manner.

Wmind wear is HBase?

HBase is a distributed column-oriented database built on top of the Hadoop file system. It is an open up-source project and is horizontally scalable.

HBase is a data model tmind wear is similar to Google’s big table styleed to provide fast random access to huge amounts of structured-coloureddish data. It leverages the fault tolerance provided simply simply by the Hadoop File System (HDFS).

It is a part of the Hadoop ecosystem tmind wear provides random real-time read/write access to data in the Hadoop File System.

One can store the data in HDFS possibly immediately or through HBase. Data consumer reads/accesses the data in HDFS randomly uperform HBase. HBase sit is on top of the Hadoop File System and provides read and write access.

HBase Flow

HBase and HDFS

HDFS HBase
HDFS is a distributed file system suitable for storing huge files. HBase is a database built on top of the HDFS.
HDFS does not support fast individual record lookups. HBase provides fast lookups for huger tables.
It provides high latency batch procesperform; no concept of batch procesperform. It provides low latency access to performle rows from billions of records (Random access).
It provides only sequential access of data. HBase internally uses Hash tables and provides random access, and it stores the data in indexed HDFS files for faster lookups.

Storage Mechanism in HBase

HBase is a column-oriented database and the tables in it are sorted simply simply by row. The table schema degreats only column famisit is, which are the key value pairs. A table have multiple column famisit is and every column family can have any kind of numbecomer of columns. Subsequent column values are stored-coloureddish contiguously on the disk. Each cell value of the table has a timestamp. In short, in an HBase:

  • Table is a collection of rows.
  • Row is a collection of column famisit is.
  • Column family is a collection of columns.
  • Column is a collection of key value pairs.

Given becomelow is an example schema of table in HBase.

Rowid Column Family Column Family Column Family Column Family
col1 col2 col3 col1 col2 col3 col1 col2 col3 col1 col2 col3
1
2
3

Column Oriented and Row Oriented

Column-oriented databases are those tmind wear store data tables as sections of columns of data, rather than as rows of data. Shortly, they will have column famisit is.

Row-Oriented Database Column-Oriented Database
It is suitable for Oncollection Transtake actionion Process (OLTP). It is suitable for Oncollection Analytical Procesperform (OLAP).
Such databases are styleed for small numbecomer of rows and columns. Column-oriented databases are styleed for huge tables.

The folloearng image shows column famisit is in a column-oriented database:

Table

HBase and RDBMS

HBase RDBMS
HBase is schema-less, it doesn't have the concept of fixed columns schema; degreats only column famisit is. An RDBMS is governed simply simply by it is schema, which describecomes the whole structure of tables.
It is built for wide tables. HBase is horizontally scalable. It is slim and built for small tables. Hard to dimension.
No transtake actionions are right now presently there in HBase. RDBMS is transtake actionional.
It has de-normalized data. It will have normalized data.
It is great for semi-structured-coloureddish as well as structured-coloureddish data. It is great for structured-coloureddish data.

Features of HBase

  • HBase is collectionarly scalable.
  • It has automatic failure support.
  • It provides consistent read and writes.
  • It integrates with Hadoop, both as a source and a destination.
  • It has easy java API for csitnt.
  • It provides data replication acombination clusters.

Where to Use HBase

  • Apache HBase is used to have random, real-time read/write access to Big Data.

  • It hosts very huge tables on top of clusters of commodity hardbattlee.

  • Apache HBase is a non-relational database modeimmediateed after Google's Bigtable. Bigtable take actions up on Google File System, likewise Apache HBase works on top of Hadoop and HDFS.

Applications of HBase

  • It is used whenever right now presently there is a need to write weighty applications.
  • HBase is used whenever we need to provide fast random access to available data.
  • Companies such as Facebook, Twitter, Yahoo, and Adobecome use HBase internally.

HBase History

Year Event
Nov 2006 Google relresitved the paper on BigTable.
Feb 2007 Initial HBase prototype was maked as a Hadoop contribution.
Oct 2007 The very very first usable HBase asizey with Hadoop 0.15.0 was relresitved.
Jan 2008 HBase becomecame the sub project of Hadoop.
Oct 2008 HBase 0.18.1 was relresitved.
Jan 2009 HBase 0.19.0 was relresitved.
Sept 2009 HBase 0.20.0 was relresitved.
May 2010 HBase becomecame Apache top-level project.

HBase – Architecture

In HBase, tables are split into areas and are served simply simply by the area servers. Regions are vertically divided simply simply by column famisit is into “Stores”. Stores are saved as files in HDFS. Shown becomelow is the architecture of HBase.

Note: The term ‘store’ is used for areas to exsimple the storage structure.

HBase Architecture

HBase has three major components: the csitnt library, a master server, and area servers. Region servers can become added or removed as per requirement.

MasterServer

The master server –

  • Assigns areas to the area servers and gets the help of Apache ZooKeeper for this particular particular task.

  • Handles load balancing of the areas acombination area servers. It unloads the hectic servers and shifts the areas to less occupied servers.

  • Maintains the state of the cluster simply simply by negotiating the load balancing.

  • Is responsible for schema modifys and other metadata operations such as creation of tables and column famisit is.

Regions

Regions are absolutely noslimg but tables tmind wear are split up and spread acombination the area servers.

Region server

The area servers have areas tmind wear –

  • Communicate with the csitnt and handle data-related operations.
  • Handle read and write requests for all the areas below it.
  • Decide the dimension of the area simply simply by folloearng the area dimension thresholds.

When we get a deeper look into the area server, it contain areas and stores as shown becomelow:

Regional Server

The store contains memory store and HFiles. Memstore is simply like a cache memory. Anyslimg tmind wear is entered-coloureddish into the HBase is stored-coloureddish here preliminaryly. Later, the data is transferred-coloureddish and saved in Hfiles as blocks and the memstore is flushed.

Zookeeper

  • Zookeeper is an open up-source project tmind wear provides services like maintaining configuration information, naming, providing distributed synchronization, etc.

  • Zookeeper has ephemeral nodes representing various area servers. Master servers use these nodes to discover available servers.

  • In addition to availcapacity, the nodes are furthermore used to track server failures or ne2rk partitions.

  • Csitnts communicate with area servers via zookeeper.

  • In pseudo and standaperformle modes, HBase it iself will get care of zookeeper.

HBase – Installation

This chapter exsimples how HBase is instalimmediateed and preliminaryly configured-coloureddish. Java and
Hadoop are required-coloureddish to proceed with HBase, so you have to download and install
java and Hadoop in your own system.

Pre-Installation Setup

Before installing Hadoop into Linux environment, we need to set up Linux uperform ssh (Secure Shell). Follow the steps given becomelow for setting up the Linux environment.

Creating a User

First of all, it is recommended to make a separate user for Hadoop to isolate the Hadoop file system from the Unix file system. Follow the steps given becomelow to make a user.

  • Open the underlying uperform the command “su”.
  • Create a user from the underlying account uperform the command “useradd username”.
  • Now you can open up an existing user account uperform the command “su username”.

Open the Linux terminal and type the folloearng commands to make a user.

$ su
compalloweword:
# useradd hadoop
# compallowewd hadoop
New compallowewd:
Retype brand new compallowewd

SSH Setup and Key Generation

SSH setup is required-coloureddish to perform various operations on the cluster such as start, end, and distributed daemon shell operations. To authenticate various users of Hadoop, it is required-coloureddish to provide public/private key pair for a Hadoop user and share it with various users.

The folloearng commands are used to generate a key value pair uperform SSH. Copy the public keys form id_rsa.pub to authorised_keys, and provide owner, read and write permissions to authorised_keys file respectively.

$ ssh-keygen -t rsa
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorised_keys
$ chmod 0600 ~/.ssh/authorised_keys

Verify ssh

ssh localhost

Installing Java

Java is the main prerequisite for Hadoop and HBase. First of all, you ought to verify the existence of java in your own system uperform “java -version”. The syntax of java version command is given becomelow.

$ java -version

If everyslimg works great, it will give you the folloearng awayplace.

java version "1.7.0_71"
Java(TM) SE Runtime Environment (make 1.7.0_71-b13)
Java HotSpot(TM) Csitnt VM (make 25.0-b02, mixed mode)

If java is not instalimmediateed in your own system, then follow the steps given becomelow for installing java.

Step 1

Download java (JDK <latest version> – X64.tar.gz) simply simply by visiting the folloearng link Oracle Java.

Then jdk-7u71-linux-x64.tar.gz will become downloaded into your own system.

Step 2

Generally you will find the downloaded java file in Downloads folder. Verify it and extrtake action the jdk-7u71-linux-x64.gz file uperform the folloearng commands.

$ cd Downloads/
$ ls
jdk-7u71-linux-x64.gz

$ tar zxf jdk-7u71-linux-x64.gz
$ ls
jdk1.7.0_71 jdk-7u71-linux-x64.gz

Step 3

To make java available to all the users, you have to move it to the location “/usr/local/”. Open underlying and type the folloearng commands.

$ su
compalloweword:
# mv jdk1.7.0_71 /usr/local/
# exit

Step 4

For setting up PATH and JAVA_HOME variables, add the folloearng commands to ~/.bashrc file.

export JAVA_HOME=/usr/local/jdk1.7.0_71
export PATH= $PATH:$JAVA_HOME/bin

Now apply all the modifys into the current operatening system.

$ source ~/.bashrc

Step 5

Use the folloearng commands to configure java alternatives:

# alternatives --install /usr/bin/java java usr/local/java/bin/java 2

# alternatives --install /usr/bin/javac javac usr/local/java/bin/javac 2

# alternatives --install /usr/bin/jar jar usr/local/java/bin/jar 2


# alternatives --set java usr/local/java/bin/java

# alternatives --set javac usr/local/java/bin/javac

# alternatives --set jar usr/local/java/bin/jar

Now verify the java -version command from the terminal as exsimpleed above.

Downloading Hadoop

After installing java, you have to install Hadoop. First of all, verify the existence of Hadoop uperform “ Hadoop version ” command as shown becomelow.

hadoop version

If everyslimg works great, it will give you the folloearng awayplace.

Hadoop 2.6.0
Compiimmediateed simply simply by jenkins on 2014-11-13T21:10Z
Compiimmediateed with protoc 2.5.0
From source with checksum 18e43357c8f927c0695f1e9522859d6a
This command was operate uperform
/home/hadoop/hadoop/share/hadoop/common/hadoop-common-2.6.0.jar

If your own system is unable to locate Hadoop, then download Hadoop in your own system. Follow the commands given becomelow to do so.

Download and extrtake action hadoop-2.6.0 from Apache Softbattlee Foundation uperform the folloearng commands.

$ su
compalloweword:
# cd /usr/local
# wget http://mirrors.advancedhosters.com/apache/hadoop/common/hadoop-
2.6.0/hadoop-2.6.0-src.tar.gz
# tar xzf hadoop-2.6.0-src.tar.gz
# mv hadoop-2.6.0/* hadoop/
# exit

Installing Hadoop

Install Hadoop in any kind of of the required-coloureddish mode. Here, we are demonstrating HBase functionalitie up ups in pseudo distributed mode, right now presently therefore install Hadoop in pseudo distributed mode.

The folloearng steps are used for installing Hadoop 2.4.1.

Step 1 – Setting up Hadoop

You can set Hadoop environment variables simply simply by appending the folloearng commands to ~/.bashrc file.

export HADOOP_HOME=/usr/local/hadoop
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export YARN_HOME=$HADOOP_HOME
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin
export HADOOP_INSTALL=$HADOOP_HOME

Now apply all the modifys into the current operatening system.

$ source ~/.bashrc

Step 2 – Hadoop Configuration

You can find all the Hadoop configuration files in the location “$HADOOP_HOME/etc/hadoop”. You need to make modifys in those configuration files according to your own Hadoop infrastructure.

$ cd $HADOOP_HOME/etc/hadoop

In order to make Hadoop programs in java, you have to reset the java environment variable in hadoop-env.sh file simply simply by replacing JAVA_HOME value with the location of java in your own system.

export JAVA_HOME=/usr/local/jdk1.7.0_71

You will have to edit the folloearng files to configure Hadoop.

core-site.xml

The core-site.xml file contains information such as the port numbecomer used for Hadoop instance, memory allocated for file system, memory limit for storing data, and the dimension of Read/Write buffers.

Open core-site.xml and add the folloearng propertie up ups in becometween the <configuration> and </configuration> tags.

<configuration>
   <real estate>
      <name>fs.default.name</name>
      <value>hdfs://localhost:9000</value>
   </real estate>
</configuration>

hdfs-site.xml

The hdfs-site.xml file contains information such as the value of replication data, namenode route, and datanode route of your own local file systems, where you like to store the Hadoop infrastructure.

Let us bumume the folloearng data.

dfs.replication (data replication value) = 1
(In the becomelow given route /hadoop/ is the user name.
hadoopinfra/hdfs/namenode is the immediateory maked simply simply by hdfs file system.)

namenode route = //home/hadoop/hadoopinfra/hdfs/namenode
(hadoopinfra/hdfs/datanode is the immediateory maked simply simply by hdfs file system.)

datanode route = //home/hadoop/hadoopinfra/hdfs/datanode

Open this particular particular file and add the folloearng propertie up ups in becometween the <configuration>, </configuration> tags.

<configuration>
   <real estate>
      <name>dfs.replication</name >
      <value>1</value>
   </real estate>
	
   <real estate>
      <name>dfs.name.dir</name>
      <value>file:///home/hadoop/hadoopinfra/hdfs/namenode</value>
   </real estate>
	
   <real estate>
      <name>dfs.data.dir</name>
      <value>file:///home/hadoop/hadoopinfra/hdfs/datanode</value>
   </real estate>
</configuration>

Note: In the above file, all the real estate values are user-degreatd and you can make modifys according to your own Hadoop infrastructure.

yarn-site.xml

This file is used to configure yarn into Hadoop. Open the yarn-site.xml file and add the folloearng real estate in becometween the <configuration$gt;, </configuration$gt; tags in this particular particular file.

<configuration>
   <real estate>
      <name>yarn.nodemanager.aux-services</name>
      <value>chartred-coloureddishuce_shuffle</value>
   </real estate>
</configuration>

chartred-coloureddish-site.xml

This file is used to specify which MapReduce framework we are uperform. By default, Hadoop contains a template of yarn-site.xml. First of all, it is required-coloureddish to duplicate the file from chartred-coloureddish-site.xml.template to chartred-coloureddish-site.xml file uperform the folloearng command.

$ cp chartred-coloureddish-site.xml.template chartred-coloureddish-site.xml

Open chartred-coloureddish-site.xml file and add the folloearng propertie up ups in becometween the <configuration> and </configuration> tags.

<configuration>
   <real estate>
      <name>chartred-coloureddishuce.framework.name</name>
      <value>yarn</value>
   </real estate>
</configuration>

Verifying Hadoop Installation

The folloearng steps are used to verify the Hadoop installation.

Step 1 – Name Node Setup

Set up the namenode uperform the command “hdfs namenode -format” as follows.

$ cd ~
$ hdfs namenode -format

The expected result is as follows.

10/24/14 21:30:55 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: host = localhost/192.168.1.11
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 2.4.1
...
...
10/24/14 21:30:56 INFO common.Storage: Storage immediateory
/home/hadoop/hadoopinfra/hdfs/namenode has becomeen successcomppermitey formatted.
10/24/14 21:30:56 INFO namenode.NNStorageRetentionManager: Going to
retain 1 images with txid >= 0
10/24/14 21:30:56 INFO util.ExitUtil: Exiting with status 0
10/24/14 21:30:56 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at localhost/192.168.1.11
************************************************************/

Step 2 – Verifying Hadoop dfs

The folloearng command is used to start dfs. Executing this particular particular command will start your own Hadoop file system.

$ start-dfs.sh

The expected awayplace is as follows.

10/24/14 21:37:56
Starting namenodes on [localhost]
localhost: starting namenode, logging to /home/hadoop/hadoop-
2.4.1/logs/hadoop-hadoop-namenode-localhost.away
localhost: starting datanode, logging to /home/hadoop/hadoop-
2.4.1/logs/hadoop-hadoop-datanode-localhost.away
Starting 2ndary namenodes [0.0.0.0]

Step 3 – Verifying Yarn Script

The folloearng command is used to start the yarn script. Executing this particular particular command will start your own yarn daemons.

$ start-yarn.sh

The expected awayplace is as follows.

starting yarn daemons
starting resourcemanager, logging to /home/hadoop/hadoop-
2.4.1/logs/yarn-hadoop-resourcemanager-localhost.away
localhost: starting nodemanager, logging to /home/hadoop/hadoop-
2.4.1/logs/yarn-hadoop-nodemanager-localhost.away

Step 4 – Accesperform Hadoop on Browser

The default port numbecomer to access Hadoop is 50070. Use the folloearng url to get Hadoop services on your own browser.

http://localhost:50070

Hadoop on Browser

Step 5 – Verify all Applications of Cluster

The default port numbecomer to access all the applications of cluster is 8088. Use the folloearng url to visit this particular particular service.

http://localhost:8088/

Hadoop Applicatin Cluster

Installing HBase

We can install HBase in any kind of of the three modes: Standaperformle mode, Pseudo Distributed mode, and Fully Distributed mode.

Installing HBase in Standaperformle Mode

Download the latest stable version of HBase form /index.php?s=httpwwearnterior-dsgncochartachehbasestable uperform “wget” command, and extrtake action it uperform the tar “zxvf” command. See the folloearng command.

$cd usr/local/
$wget /index.php?s=httpwwearnterior-dsgncochartachehbasestablehbase-0.98.8-
hadoop2-bin.tar.gz
$tar -zxvf hbase-0.98.8-hadoop2-bin.tar.gz

Shift to super user mode and move the HBase folder to /usr/local as shown becomelow.

$su
$compalloweword: enter your own compalloweword here
mv hbase-0.99.1/* Hbase/

Configuring HBase in Standaperformle Mode

Before proceeding with HBase, you have to edit the folloearng files and configure HBase.

hbase-env.sh

Set the java Home for HBase and open up hbase-env.sh file from the conf folder. Edit JAVA_HOME environment variable and modify the existing route to your own current JAVA_HOME variable as shown becomelow.

cd /usr/local/Hbase/conf
gedit hbase-env.sh

This will open up the env.sh file of HBase. Now replace the existing JAVA_HOME value with your own current value as shown becomelow.

export JAVA_HOME=/usr/lib/jvm/java-1.7.0

hbase-site.xml

This is the main configuration file of HBase. Set the data immediateory to an appropriate location simply simply by open uping the HBase home folder in /usr/local/HBase. Inaspect the conf folder, you will find many kind of files, open up the hbase-site.xml file as shown becomelow.

#cd /usr/local/HBase/
#cd conf
# gedit hbase-site.xml

Inaspect the hbase-site.xml file, you will find the <configuration> and
</configuration> tags. Wislim them, set the HBase immediateory below the real estate
key with the name “hbase.underlyingdir” as shown becomelow.

<configuration>
   //Here you have to set the route where you like HBase to store it is files.
   <real estate>
      <name>hbase.underlyingdir</name>
      <value>file:/home/hadoop/HBase/HFiles</value>
   </real estate>
	
   //Here you have to set the route where you like HBase to store it is built in zookeeper  files.
   <real estate>
      <name>hbase.zookeeper.real estate.dataDir</name>
      <value>/home/hadoop/zookeeper</value>
   </real estate>
</configuration>

With this particular particular, the HBase installation and configuration part is successcomppermitey overallll. We can start HBase simply simply by uperform start-hbase.sh script provided in the bin folder of HBase. For tmind wear, open up HBase Home Folder and operate HBase start script as shown becomelow.

$cd /usr/local/HBase/bin
$./start-hbase.sh

If everyslimg goes well, when you conaspectr to operate HBase start script, it will prompt you a message saying tmind wear HBase has started.

starting master, logging to /usr/local/HBase/bin/../logs/hbase-tpmaster-localhost.localdomain.away

Installing HBase in Pseudo-Distributed Mode

Let us now check how HBase is instalimmediateed in pseudo-distributed mode.

Configuring HBase

Before proceeding with HBase, configure Hadoop and HDFS on your own local system or on a remote system and make sure they are operatening. Stop HBase if it is operatening.

hbase-site.xml

Edit hbase-site.xml file to add the folloearng propertie up ups.

<real estate>
   <name>hbase.cluster.distributed</name>
   <value>true</value>
</real estate>

It will mention in which mode HBase ought to become operate. In the extake action same file from the local file system, modify the hbase.underlyingdir, your own HDFS instance adoutfit, uperform the hdfs://// URI syntax. We are operatening HDFS on the localhost at port 8030.

<real estate>
   <name>hbase.underlyingdir</name>
   <value>hdfs://localhost:8030/hbase</value>
</real estate>

Starting HBase

After configuration is over, browse to HBase home folder and start HBase uperform the folloearng command.

$cd /usr/local/HBase
$bin/start-hbase.sh

Note: Before starting HBase, make sure Hadoop is operatening.

Checruler the HBase Directory in HDFS

HBase makes it is immediateory in HDFS. To see the maked immediateory, browse to Hadoop bin and type the folloearng command.

$ ./bin/hadoop fs -ls /hbase

If everyslimg goes well, it will give you the folloearng awayplace.

Found 7 items
drwxr-xr-x - hbase users 0 2014-06-25 18:58 /hbase/.tmp
drwxr-xr-x - hbase users 0 2014-06-25 21:49 /hbase/WALs
drwxr-xr-x - hbase users 0 2014-06-25 18:48 /hbase/corrupt
drwxr-xr-x - hbase users 0 2014-06-25 18:58 /hbase/data
-rw-r--r-- 3 hbase users 42 2014-06-25 18:41 /hbase/hbase.id
-rw-r--r-- 3 hbase users 7 2014-06-25 18:41 /hbase/hbase.version
drwxr-xr-x - hbase users 0 2014-06-25 21:49 /hbase/oldWALs

Starting and Stopping a Master

Uperform the “local-master-backup.sh” you can start up to 10 servers. Open the home folder of HBase, master and execute the folloearng command to start it.

$ ./bin/local-master-backup.sh 2 4

To destroy a backup master, you need it is process id, which will become stored-coloureddish in a file named “/tmp/hbase-USER-X-master.pid.” you can destroy the backup master uperform the folloearng command.

$ cat /tmp/hbase-user-1-master.pid |xargs destroy -9

Starting and Stopping RegionServers

You can operate multiple area servers from a performle system uperform the folloearng command.

$ .bin/local-areaservers.sh start 2 3

To end a area server, use the folloearng command.

$ .bin/local-areaservers.sh end 3

 

Starting HBaseShell

After Installing HBase successcomppermitey, you can start HBase Shell. Below given are the sequence of steps tmind wear are to become followed to start the HBase shell. Open the terminal, and login as super user.

Start Hadoop File System

Browse through Hadoop home sbin folder and start Hadoop file system as shown becomelow.

$cd $HADOOP_HOME/sbin
$start-all.sh

Start HBase

Browse through the HBase underlying immediateory bin folder and start HBase.

$cd /usr/local/HBase
$./bin/start-hbase.sh

Start HBase Master Server

This will become the extake action same immediateory. Start it as shown becomelow.

$./bin/local-master-backup.sh start 2 (numbecomer signifies specific
server.) 

Start Region

Start the area server as shown becomelow.

$./bin/./local-areaservers.sh start 3

Start HBase Shell

You can start HBase shell uperform the folloearng command.

$cd bin
$./hbase shell

This will give you the HBase Shell Prompt as shown becomelow.

2014-12-09 14:24:27,526 INFO [main] Configuration.deprecation:
hadoop.native.lib is deprecated. Instead, use io.native.lib.available
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to depart the HBase Shell
Version 0.98.8-hadoop2, r6cfc8d064754251365e070a10a82eb169956d5fe, Fri
Nov 14 18:26:29 PST 2014

hbase(main):001:0>

HBase Web Interface

To access the web interface of HBase, type the folloearng url in the browser.

http://localhost:60010

This interface lists your own currently operatening Region servers, backup masters and HBase tables.

HBase Region servers and Backup Masters

HBase Servers

HBase Tables

HBase Tables

Setting Java Environment

We can furthermore communicate with HBase uperform Java libraries, but becomefore accesperform HBase uperform Java API you need to set courseroute for those libraries.

Setting the Clbumroute

Before proceeding with programming, set the courseroute to HBase libraries in .bashrc file. Open .bashrc in any kind of of the editors as shown becomelow.

$ gedit ~/.bashrc

Set courseroute for HBase libraries (lib folder in HBase) in it as shown becomelow.

export CLASSPATH = $CLASSPATH://home/hadoop/hbase/lib/*

This is to pralsot the “course not found” exception while accesperform the HBase uperform java API.

HBase – Shell

This chapter exsimples how to start HBase intertake actionive shell tmind wear comes asizey with HBase.

HBase Shell

HBase contains a shell uperform which you can communicate with HBase. HBase uses the Hadoop File System to store it is data. It will have a master server and area servers. The data storage will become in the form of areas (tables). These areas will become split up and stored-coloureddish in area servers.

The master server manages these area servers and all these tasks get place on HDFS. Given becomelow are some of the commands supported simply simply by HBase Shell.

General Commands

  • status – Provides the status of HBase, for example, the numbecomer of servers.

  • version – Provides the version of HBase becomeing used.

  • table_help – Provides help for table-reference commands.

  • whoami – Provides information abaway the user.

Data Definition Language

These are the commands tmind wear operate on the tables in HBase.

  • make – Creates a table.

  • list – Lists all the tables in HBase.

  • disable – Disables a table.

  • is_disabimmediateed – Verifies whether a table is disabimmediateed.

  • enable – Enables a table.

  • is_enabimmediateed – Verifies whether a table is enabimmediateed.

  • describecome – Provides the description of a table.

  • alter – Alters a table.

  • exists – Verifies whether a table exists.

  • fall – Drops a table from HBase.

  • fall_all – Drops the tables fiting the ‘regex’ given in the command.

  • Java Admin API – Prior to all the above commands, Java provides an Admin API to achieve DDL functionalitie up ups through programming. Under org.apache.hadoop.hbase.csitnt package, HBaseAdmin and
    HTableDescriptor are the 2 important coursees in this particular particular package tmind wear provide DDL functionalitie up ups.

Data Manipulation Language

  • place – Puts a cell value at a specified column in a specified row in a
    particular table.

  • get – Fetches the contents of row or a cell.

  • depermite – Depermites a cell value in a table.

  • depermiteall – Depermites all the cells in a given row.

  • scan – Scans and returns the table data.

  • count – Counts and returns the numbecomer of rows in a table.

  • toperatecate – Disables, falls, and red-colouremakes a specified table.

  • Java csitnt API – Prior to all the above commands, Java provides a csitnt API to achieve DML functionalitie up ups, CRUD (Create Retrieve Update Depermite) operations and more through programming, below org.apache.hadoop.hbase.csitnt package. HTable Put and Get are the important coursees in this particular particular package.

Starting HBase Shell

To access the HBase shell, you have to navigate to the HBase home folder.

cd /usr/localhost/
cd Hbase

You can start the HBase intertake actionive shell uperform “hbase shell” command as shown becomelow.

./bin/hbase shell

If you have successcomppermitey instalimmediateed HBase in your own system, then it gives you the HBase shell prompt as shown becomelow.

HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to depart the HBase Shell
Version 0.94.23, rf42302b28aceaab773b15f234aa8718fff7eea3c, Wed Aug 27
00:54:09 UTC 2014

hbase(main):001:0>

To exit the intertake actionive shell command at any kind of moment, type exit or use <ctrl+c>. Check the shell functioning becomefore proceeding further. Use the list command for this particular particular purpose. List is a command used to get the list of all the tables in HBase. First of all, verify the installation and the configuration of HBase in your own system uperform this particular particular command as shown becomelow.

hbase(main):001:0> list

When you type this particular particular command, it gives you the folloearng awayplace.

hbase(main):001:0> list
TABLE

HBase – General Commands

The general commands in HBase are status, version, table_help, and whoami. This chapter exsimples these commands.

status

This command returns the status of the system including the details of the servers operatening on the system. It’s syntax is as follows:

hbase(main):009:0> status

If you execute this particular particular command, it returns the folloearng awayplace.

hbase(main):009:0> status
3 servers, 0 dead, 1.3333 average load

version

This command returns the version of HBase used in your own system. It’s syntax is as follows:

hbase(main):010:0> version

If you execute this particular particular command, it returns the folloearng awayplace.

hbase(main):009:0> version
0.98.8-hadoop2, r6cfc8d064754251365e070a10a82eb169956d5fe, Fri Nov 14
18:26:29 PST 2014

table_help

This command guides you extake actionly wmind wear and how to use table-referenced commands. Given becomelow is the syntax to use this particular particular command.

hbase(main):02:0> table_help

When you use this particular particular command, it shows help topics for table-related commands. Given becomelow is the partial awayplace of this particular particular command.

hbase(main):002:0> table_help
Help for table-reference commands.
You can possibly make a table via 'make' and then manipulate the table
via commands like 'place', 'get', etc.
See the standard help information for how to use every of these commands.
However, as of 0.96, you can furthermore get a reference to a table, on which
you can invoke commands.
For instance, you can get make a table and keep around a reference to
it via:
 hbase> t = make 't', 'cf'…...

whoami

This command returns the user details of HBase. If you execute this particular particular command, returns the current HBase user as shown becomelow.

hbase(main):008:0> whoami
hadoop (auth:SIMPLE)
groups: hadoop

HBase – Admin API

HBase is written in java, right now presently therefore it provides java API to communicate with HBase. Java API is the fastest way to communicate with HBase. Given becomelow is the referenced java Admin API tmind wear covers the tasks used to manage tables.

Clbum HBaseAdmin

HBaseAdmin is a course representing the Admin. This course becomesizeys to the org.apache.hadoop.hbase.csitnt package. Uperform this particular particular course, you can perform the tasks of an administrator. You can get the instance of Admin uperform Connection.getAdmin() method.

Methods and Description

S.No. Methods and Description
1

void makeTable(HTableDescriptor desc)

Creates a brand new table.

2

void makeTable(HTableDescriptor desc, simply simply byte[][] splitKeys)

Creates a brand new table with an preliminary set of empty areas degreatd simply simply by the specified split keys.

3

void depermiteColumn(simply simply byte[] tableName, String columnName)

Depermites a column from a table.

4

void depermiteColumn(String tableName, String columnName)

Depermite a column from a table.

5

void depermiteTable(String tableName)

Depermites a table.

Clbum Descriptor

This course contains the details abaway an HBase table such as:

  • the descriptors of all the column famisit is,
  • if the table is a catalog table,
  • if the table is read only,
  • the maximum dimension of the mem store,
  • when the area split ought to occur,
  • co-processors bumociated with it, etc.

Constructors

S.No. Constructor and summary
1

HTableDescriptor(TableName name)

Constructs a table descriptor specifying a TableName object.

Methods and Description

S.No. Methods and Description
1

HTableDescriptor addFamily(HColumnDescriptor family)

Adds a column family to the given descriptor

HBase – Create Table

Creating a Table uperform HBase Shell

You can make a table uperform the make command, here you must specify the table name and the Column Family name. The syntax to make a table in HBase shell is shown becomelow.

make ‘<table name>’,’<column family>’ 

Example

Given becomelow is a sample schema of a table named emp. It has 2 column famisit is: “individual data” and “professional data”.

Row key individual data professional data

You can make this particular particular table in HBase shell as shown becomelow.

hbase(main):002:0> make 'emp', 'individual data', ’professional data’

And it will give you the folloearng awayplace.

0 row(s) in 1.1300 2nds
=> Hbase::Table - emp

Verification

You can verify whether the table is maked uperform the list command as shown becomelow. Here you can observe the maked emp table.

hbase(main):002:0> list
TABLE 
emp
2 row(s) in 0.0340 2nds

Creating a Table Uperform java API

You can make a table in HBase uperform the makeTable() method of HBaseAdmin course. This course becomesizeys to the org.apache.hadoop.hbase.csitnt package. Given becomelow are the steps to make a table in HBase uperform java API.

Step1: Instantiate HBaseAdmin

This course requires the Configuration object as a parameter, right now presently therefore preliminaryly immediateiate the Configuration course and compallowe this particular particular instance to HBaseAdmin.

Configuration conf = HBaseConfiguration.make();
HBaseAdmin admin = brand new HBaseAdmin(conf);

Step2: Create TableDescriptor

HTableDescriptor is a course tmind wear becomesizeys to the org.apache.hadoop.hbase course. This course is like a container of table names and column famisit is.

//creating table descriptor
HTableDescriptor table = brand new HTableDescriptor(toBytes("Table name"));

//creating column family descriptor
HColumnDescriptor family = brand new HColumnDescriptor(toBytes("column family"));

//adding coloumn family to HTable
table.addFamily(family);

Step 3: Execute through Admin

Uperform the makeTable() method of HBaseAdmin course, you can execute the maked table in Admin mode.

admin.makeTable(table);

Given becomelow is the overallll program to make a table via admin.

import java.io.IOException;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.csitnt.HBaseAdmin;
import org.apache.hadoop.hbase.TableName;

import org.apache.hadoop.conf.Configuration;

public course CreateTable {
      
   public static void main(String[] args) throws IOException {

      // Instantiating configuration course
      Configuration con = HBaseConfiguration.make();

      // Instantiating HbaseAdmin course
      HBaseAdmin admin = brand new HBaseAdmin(con);

      // Instantiating table descriptor course
      HTableDescriptor tableDescriptor = brand new
      TableDescriptor(TableName.valueOf("emp"));

      // Adding column famisit is to table descriptor
      tableDescriptor.addFamily(brand new HColumnDescriptor("individual"));
      tableDescriptor.addFamily(brand new HColumnDescriptor("professional"));

      // Execute the table through admin
      admin.makeTable(tableDescriptor);
      System.away.println(" Table maked ");
   }
}

Compile and execute the above program as shown becomelow.

$javac CreateTable.java
$java CreateTable

The folloearng ought to become the awayplace:

Table maked

HBase – Listing Table

Listing a Table uperform HBase Shell

list is the command tmind wear is used to list all the tables in HBase. Given becomelow is the syntax of the list command.

hbase(main):001:0 > list

When you type this particular particular command and execute in HBase prompt, it will display the list of all the tables in HBase as shown becomelow.

hbase(main):001:0> list
TABLE
emp

Here you can observe a table named emp.

Listing Tables Uperform Java API

Follow the steps given becomelow to get the list of tables from HBase uperform java API.

Step 1

You have a method calimmediateed listTables() in the course HBaseAdmin to get the list of all the tables in HBase. This method returns an array of HTableDescriptor objects.

//creating a configuration object
Configuration conf = HBaseConfiguration.make();

//Creating HBaseAdmin object
HBaseAdmin admin = brand new HBaseAdmin(conf);

//Getting all the list of tables uperform HBaseAdmin object
HTableDescriptor[] tableDescriptor = admin.listTables();

Step 2

You can get the size of the HTableDescriptor[] array uperform the size variable of the HTableDescriptor course. Get the name of the tables from this particular particular object uperform getNameAsString() method. Run the ‘for’ loop uperform these and get the list of the tables in HBase.

Given becomelow is the program to list all the tables in HBase uperform Java API.

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.csitnt.HBaseAdmin;

public course ListTables {

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

      // Instantiating a configuration course
      Configuration conf = HBaseConfiguration.make();

      // Instantiating HBaseAdmin course
      HBaseAdmin admin = brand new HBaseAdmin(conf);

      // Getting all the list of tables uperform HBaseAdmin object
      HTableDescriptor[] tableDescriptor = admin.listTables();

      // printing all the table names.
      for (int i=0; i<tableDescriptor.size;i++ ){
         System.away.println(tableDescriptor[i].getNameAsString());
      }
   
   }
}

Compile and execute the above program as shown becomelow.

$javac ListTables.java
$java ListTables

The folloearng ought to become the awayplace:

User
emp

HBase – Disabling a Table

Disabling a Table uperform HBase Shell

To depermite a table or modify it is settings, you need to very very first disable the table uperform the disable command. You can re-enable it uperform the enable command.

Given becomelow is the syntax to disable a table:

disable ‘emp’

Example

Given becomelow is an example tmind wear shows how to disable a table.

hbase(main):025:0> disable 'emp'
0 row(s) in 1.2760 2nds

Verification

After disabling the table, you can still sense it is existence through list and exists commands. You cannot scan it. It will give you the folloearng error.

hbase(main):028:0> scan 'emp'
ROW         COLUMN + CELL
ERROR: emp is disabimmediateed.

is_disabimmediateed

This command is used to find whether a table is disabimmediateed. It’s syntax is as follows.

hbase> is_disabimmediateed 'table name'

The folloearng example verifies whether the table named emp is disabimmediateed. If it is disabimmediateed, it will return true and if not, it will return false.

hbase(main):031:0> is_disabimmediateed 'emp'
true
0 row(s) in 0.0440 2nds

disable_all

This command is used to disable all the tables fiting the given regex. The syntax for disable_all command is given becomelow.

hbase> disable_all 'r.*'

Suppose right now presently there are 5 tables in HBase, namely raja, rajani, rajendra, rajesh, and
raju. The folloearng code will disable all the tables starting with raj.

hbase(main):002:07> disable_all 'raj.*'
raja
rajani
rajendra
rajesh
raju
Disable the above 5 tables (y/n)?
y
5 tables successcomppermitey disabimmediateed

Disable a Table Uperform Java API

To verify whether a table is disabimmediateed, isTableDisabimmediateed() method is used and to disable a table, disableTable() method is used. These methods becomesizey to the HBaseAdmin course. Follow the steps given becomelow to disable a table.

Step 1

Instantiate HBaseAdmin course as shown becomelow.

// Creating configuration object
Configuration conf = HBaseConfiguration.make();

// Creating HBaseAdmin object
HBaseAdmin admin = brand new HBaseAdmin(conf);

Step 2

Verify whether the table is disabimmediateed uperform isTableDisabimmediateed() method as shown becomelow.

Boolean b = admin.isTableDisabimmediateed("emp");

Step 3

If the table is not disabimmediateed, disable it as shown becomelow.

if(!b){
   admin.disableTable("emp");
   System.away.println("Table disabimmediateed");
}

Given becomelow is the overallll program to verify whether the table is disabimmediateed; if not, how to disable it.

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.csitnt.HBaseAdmin;

public course DisableTable{

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

      // Instantiating configuration course
      Configuration conf = HBaseConfiguration.make();
 
      // Instantiating HBaseAdmin course
      HBaseAdmin admin = brand new HBaseAdmin(conf);

      // Verifying weather conditions conditions the table is disabimmediateed
      Boolean bool = admin.isTableDisabimmediateed("emp");
      System.away.println(bool);

      // Disabling the table uperform HBaseAdmin object
      if(!bool){
         admin.disableTable("emp");
         System.away.println("Table disabimmediateed");
      }
   }
}

Compile and execute the above program as shown becomelow.

$javac DisableTable.java
$java DsiableTable

The folloearng ought to become the awayplace:

false
Table disabimmediateed

HBase – Enabling a Table

Enabling a Table uperform HBase Shell

Syntax to enable a table:

enable ‘emp’

Example

Given becomelow is an example to enable a table.

hbase(main):005:0> enable 'emp'
0 row(s) in 0.4580 2nds

Verification

After enabling the table, scan it. If you can see the schema, your own table is successcomppermitey enabimmediateed.

hbase(main):006:0> scan 'emp'

   ROW                        COLUMN + CELL

1 column = individual data:city, timestamp = 1417516501, value = hyderabad

1 column = individual data:name, timestamp = 1417525058, value = ramu

1 column = professional data:styleation, timestamp = 1417532601, value = manager

1 column = professional data:salary, timestamp = 1417524244109, value = 50000

2 column = individual data:city, timestamp = 1417524574905, value = chennai

2 column = individual data:name, timestamp = 1417524556125, value = ravi

2 column = professional data:styleation, timestamp = 14175292204, value = sr:engg

2 column = professional data:salary, timestamp = 1417524604221, value = 30000 

3 column = individual data:city, timestamp = 1417524681780, value = delhi

3 column = individual data:name, timestamp = 1417524672067, value = rajesh

3 column = professional data:styleation, timestamp = 14175246987, value = jr:engg

3 column = professional data:salary, timestamp = 1417524702514, value = 25000

3 row(s) in 0.0400 2nds

is_enabimmediateed

This command is used to find whether a table is enabimmediateed. It’s syntax is as follows:

hbase> is_enabimmediateed 'table name'

The folloearng code verifies whether the table named emp is enabimmediateed. If it is enabimmediateed, it will return true and if not, it will return false.

hbase(main):031:0> is_enabimmediateed 'emp'
true
0 row(s) in 0.0440 2nds

Enable a Table Uperform Java API

To verify whether a table is enabimmediateed, isTableEnabimmediateed() method is used; and to enable a table, enableTable() method is used. These methods becomesizey to HBaseAdmin course. Follow the steps given becomelow to enable a table.

Step1

Instantiate HBaseAdmin course as shown becomelow.

// Creating configuration object
Configuration conf = HBaseConfiguration.make();

// Creating HBaseAdmin object
HBaseAdmin admin = brand new HBaseAdmin(conf);

Step 2

Verify whether the table is enabimmediateed uperform isTableEnabimmediateed() method as shown becomelow.

Boolean bool = admin.isTableEnabimmediateed("emp");

Step 3

If the table is not disabimmediateed, disable it as shown becomelow.

if(!bool){
   admin.enableTable("emp");
   System.away.println("Table enabimmediateed");
}

Given becomelow is the overallll program to verify whether the table is enabimmediateed and if it is not, then how to enable it.

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.csitnt.HBaseAdmin;

public course EnableTable{

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

      // Instantiating configuration course
      Configuration conf = HBaseConfiguration.make();

      // Instantiating HBaseAdmin course
      HBaseAdmin admin = brand new HBaseAdmin(conf);

      // Verifying weather conditions conditions the table is disabimmediateed
      Boolean bool = admin.isTableEnabimmediateed("emp");
      System.away.println(bool);

      // Disabling the table uperform HBaseAdmin object
      if(!bool){
         admin.enableTable("emp");
         System.away.println("Table Enabimmediateed");
      }
   }
}

Compile and execute the above program as shown becomelow.

$javac EnableTable.java
$java EnableTable

The folloearng ought to become the awayplace:

false
Table Enabimmediateed

HBase – Describecome & Alter

describecome

This command returns the description of the table. It’s syntax is as follows:

hbase> describecome 'table name'

Given becomelow is the awayplace of the describecome command on the emp table.

hbase(main):006:0> describecome '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
⇒ 'individual

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

Alter is the command used to make modifys to an existing table. Uperform this particular particular command, you can modify the maximum numbecomer of cells of a column family, set and depermite table scope operators, and depermite a column family from a table.

Changing the Maximum Numbecomer of Cells of a Column Family

Given becomelow is the syntax to modify the maximum numbecomer of cells of a column family.

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

In the folloearng example, the maximum numbecomer of cells is set to 5.

hbase(main):003:0> alter 'emp', NAME ⇒ 'individual data', VERSIONS ⇒ 5
Updating all areas with the brand new schema...
0/1 areas updated.
1/1 areas updated.
Done.
0 row(s) in 2.3050 2nds

Table Scope Operators

Uperform 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 folloearng example, we have made the emp table read only.

hbase(main):006:0> alter 'emp', READONLY
Updating all areas with the brand new schema...
0/1 areas updated.
1/1 areas updated.
Done.
0 row(s) in 2.2140 2nds

Removing Table Scope Operators

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

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

Depermiting a Column Family

Uperform alter, you can furthermore depermite a column family. Given becomelow is the syntax to depermite a column family uperform alter.

hbase> alter ‘ table name ’, ‘depermite’ ⇒ ‘ column family ’ 

Given becomelow is an example to depermite a column family from the ‘emp’ table.

Assume right now presently there is a table named employee in HBase. It contains the folloearng data:

hbase(main):006:0> scan 'employee'

   ROW                   COLUMN+CELL

row1 column = individual:city, timestamp = 1418193767, value = hyderabad

row1 column = individual:name, timestamp = 1418193806767, value = raju

row1 column = professional:styleation, timestamp = 1418193767, value = manager

row1 column = professional:salary, timestamp = 1418193806767, value = 50000

1 row(s) in 0.0160 2nds 

Now permit us depermite the column family named professional uperform the alter command.

hbase(main):007:0> alter 'employee','depermite'⇒'professional'
Updating all areas with the brand new schema...
0/1 areas updated.
1/1 areas updated.
Done.
0 row(s) in 2.2380 2nds 

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

hbase(main):003:0> scan 'employee'
   ROW             COLUMN + CELL
row1 column = individual:city, timestamp = 14181936767, value = hyderabad

row1 column = individual:name, timestamp = 1418193806767, value = raju

1 row(s) in 0.0830 2nds

Adding a Column Family Uperform Java API

You can add a column family to a table uperform the method addColumn() of HBAseAdmin course. Follow the steps given becomelow to add a column family to a table.

Step 1

Instantiate the HBaseAdmin course.

// Instantiating configuration object
Configuration conf = HBaseConfiguration.make();

// Instantiating HBaseAdmin course
HBaseAdmin admin = brand new HBaseAdmin(conf); 

Step 2

The addColumn() method requires a table name and an object of HColumnDescriptor course. Therefore immediateiate the HColumnDescriptor course. The constructor of HColumnDescriptor in turn requires a column family name tmind wear is to become added. Here we are adding a column family named “conttake actionDetails” to the existing “employee” table.

// Instantiating columnDescriptor object

HColumnDescriptor columnDescriptor = brand new
HColumnDescriptor("conttake actionDetails");

Step 3

Add the column family uperform addColumn method. Pbum the table name and the HColumnDescriptor course object as parameters to this particular particular method.

// Adding column family
admin.addColumn("employee", brand new HColumnDescriptor("columnDescriptor"));

Given becomelow is the overallll program to add a column family to an existing table.

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.csitnt.HBaseAdmin;

public course AddColoumn{

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

      // Instantiating configuration course.
      Configuration conf = HBaseConfiguration.make();

      // Instantiating HBaseAdmin course.
      HBaseAdmin admin = brand new HBaseAdmin(conf);

      // Instantiating columnDescriptor course
      HColumnDescriptor columnDescriptor = brand new HColumnDescriptor("conttake actionDetails");
      
      // Adding column family
      admin.addColumn("employee", columnDescriptor);
      System.away.println("coloumn added");
   }
}

Compile and execute the above program as shown becomelow.

$javac AddColumn.java
$java AddColumn

The above compilation works only if you have set the courseroute in “ .bashrc ”. If you haven't, follow the procedure given becomelow to compile your own .java file.

//if "/home/home/hadoop/hbase " is your own Hbase home folder then.

$javac -cp /home/hadoop/hbase/lib/*: Demo.java

If everyslimg goes well, it will produce the folloearng awayplace:

column added

Depermiting a Column Family Uperform Java API

You can depermite a column family from a table uperform the method depermiteColumn() of HBAseAdmin course. Follow the steps given becomelow to add a column family to a table.

Step1

Instantiate the HBaseAdmin course.

// Instantiating configuration object
Configuration conf = HBaseConfiguration.make();

// Instantiating HBaseAdmin course
HBaseAdmin admin = brand new HBaseAdmin(conf); 

Step2

Add the column family uperform depermiteColumn() method. Pbum the table name and the column family name as parameters to this particular particular method.

// Depermiting column family
admin.depermiteColumn("employee", "conttake actionDetails"); 

Given becomelow is the overallll program to depermite a column family from an existing table.

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.csitnt.HBaseAdmin;

public course DepermiteColoumn{

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

      // Instantiating configuration course.
      Configuration conf = HBaseConfiguration.make();

      // Instantiating HBaseAdmin course.
      HBaseAdmin admin = brand new HBaseAdmin(conf);

      // Depermiting a column family
      admin.depermiteColumn("employee","conttake actionDetails");
      System.away.println("coloumn depermited"); 
   }
}

Compile and execute the above program as shown becomelow.

$javac DepermiteColumn.java
$java DepermiteColumn

The folloearng ought to become the awayplace:

column depermited

HBase – Exists

Existence of Table uperform HBase Shell

You can verify the existence of a table uperform the exists command. The folloearng example shows how to use this particular particular command.

hbase(main):024:0> exists 'emp'
Table emp does exist

0 row(s) in 0.0750 2nds

==================================================================

hbase(main):015:0> exists 'student'
Table student does not exist

0 row(s) in 0.0480 2nds

Verifying the Existence of Table Uperform Java API

You can verify the existence of a table in HBase uperform the tableExists() method of the HBaseAdmin course. Follow the steps given becomelow to verify the existence of a table in HBase.

Step 1

Instantiate the HBaseAdimn course

// Instantiating configuration object
Configuration conf = HBaseConfiguration.make();

// Instantiating HBaseAdmin course
HBaseAdmin admin = brand new HBaseAdmin(conf); 

Step 2

Verify the existence of the table uperform the tableExists( ) method.

Given becomelow is the java program to test the existence of a table in HBase uperform java API.

import java.io.IOException;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.csitnt.HBaseAdmin;

public course TableExists{

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

      // Instantiating configuration course
      Configuration conf = HBaseConfiguration.make();

      // Instantiating HBaseAdmin course
      HBaseAdmin admin = brand new HBaseAdmin(conf);

      // Verifying the existance of the table
      boolean bool = admin.tableExists("emp");
      System.away.println( bool);
   }
} 

Compile and execute the above program as shown becomelow.

$javac TableExists.java
$java TableExists 

The folloearng ought to become the awayplace:

true

HBase – Drop a Table

Dropping a Table uperform HBase Shell

Uperform the fall command, you can depermite a table. Before fallping a table, you have to disable it.

hbase(main):018:0> disable 'emp'
0 row(s) in 1.4580 2nds

hbase(main):019:0> fall 'emp'
0 row(s) in 0.3060 2nds

Verify whether the table is depermited uperform the exists command.

hbase(main):020:07gt; exists 'emp'
Table emp does not exist
0 row(s) in 0.0730 2nds

fall_all

This command is used to fall the tables fiting the “regex” given in the command. It’s syntax is as follows:

hbase> fall_all ‘t.*’ 

Note: Before fallping a table, you must disable it.

Example

Assume right now presently there are tables named raja, rajani, rajendra, rajesh, and raju.

hbase(main):017:0> list
TABLE
raja
rajani
rajendra 
rajesh
raju
9 row(s) in 0.0270 2nds

All these tables start with the permitters raj. First of all, permit us disable all these tables uperform the disable_all command as shown becomelow.

hbase(main):002:0> disable_all 'raj.*'
raja
rajani
rajendra
rajesh
raju
Disable the above 5 tables (y/n)?
y
5 tables successcomppermitey disabimmediateed

Now you can depermite all of them uperform the fall_all command as given becomelow.

hbase(main):018:0> fall_all 'raj.*'
raja
rajani
rajendra
rajesh
raju
Drop the above 5 tables (y/n)?
y
5 tables successcomppermitey fallped

Depermiting a Table Uperform Java API

You can depermite a table uperform the depermiteTable() method in the HBaseAdmin course. Follow the steps given becomelow to depermite a table uperform java API.

Step 1

Instantiate the HBaseAdmin course.

// creating a configuration object
Configuration conf = HBaseConfiguration.make();

// Creating HBaseAdmin object
HBaseAdmin admin = brand new HBaseAdmin(conf); 

Step 2

Disable the table uperform the disableTable() method of the HBaseAdmin course.

admin.disableTable("emp1");

Step 3

Now depermite the table uperform the depermiteTable() method of the HBaseAdmin course.

admin.depermiteTable("emp12");

Given becomelow is the overallll java program to depermite a table in HBase.

import java.io.IOException;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.csitnt.HBaseAdmin;

public course DepermiteTable {

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

      // Instantiating configuration course
      Configuration conf = HBaseConfiguration.make();

      // Instantiating HBaseAdmin course
      HBaseAdmin admin = brand new HBaseAdmin(conf);

      // disabling table named emp
      admin.disableTable("emp12");

      // Depermiting emp
      admin.depermiteTable("emp12");
      System.away.println("Table depermited");
   }
}

Compile and execute the above program as shown becomelow.

$javac DepermiteTable.java
$java DepermiteTable

The folloearng ought to become the awayplace:

Table depermited

HBase – Shutting Down

exit

You exit the shell simply simply by typing the exit command.

hbase(main):021:0> exit

Stopping HBase

To end HBase, browse to the HBase home folder and type the folloearng command.

./bin/end-hbase.sh

Stopping HBase Uperform Java API

You can shut down the HBase uperform the shutdown() method of the HBaseAdmin course. Follow the steps given becomelow to shut down HBase:

Step 1

Instantiate the HbaseAdmin course.

// Instantiating configuration object
Configuration conf = HBaseConfiguration.make();

// Instantiating HBaseAdmin object
HBaseAdmin admin = brand new HBaseAdmin(conf);

Step 2

Shut down the HBase uperform the shutdown() method of the HBaseAdmin course.

admin.shutdown();

Given becomelow is the program to end the HBase.

import java.io.IOException;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.csitnt.HBaseAdmin;

public course ShutDownHbase{

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

      // Instantiating configuration course
      Configuration conf = HBaseConfiguration.make();

      // Instantiating HBaseAdmin course
      HBaseAdmin admin = brand new HBaseAdmin(conf);

      // Shutting down HBase
      System.away.println("Shutting down hbase");
      admin.shutdown();
   }
}

Compile and execute the above program as shown becomelow.

$javac ShutDownHbase.java
$java ShutDownHbase

The folloearng ought to become the awayplace:

Shutting down hbase

HBase – Csitnt API

This chapter describecomes the java csitnt API for HBase tmind wear is used to perform CRUD operations on HBase tables. HBase is written in Java and has a Java Native API. Therefore it provides programmatic access to Data Manipulation Language (DML).

Clbum HBase Configuration

Adds HBase configuration files to a Configuration. This course becomesizeys to the org.apache.hadoop.hbase package.

Methods and description

S.No. Methods and Description
1

static org.apache.hadoop.conf.Configuration make()

This method makes a Configuration with HBase resources.

Clbum HTable

HTable is an HBase internal course tmind wear represents an HBase table. It is an implementation of table tmind wear is used to communicate with a performle HBase table. This course becomesizeys to the org.apache.hadoop.hbase.csitnt course.

Constructors

S.No. Constructors and Description
1

HTable()

2

HTable(TableName tableName, ClusterConnection connection, ExecutorService pool)

Uperform this particular particular constructor, you can make an object to access an HBase table.

Methods and description

S.No. Methods and Description
1

void near()

Relresitves all the resources of the HTable.

2

void depermite(Depermite depermite)

Depermites the specified cells/row.

3

boolean exists(Get get)

Uperform this particular particular method, you can test the existence of columns in the table, as specified simply simply by Get.

4

Result get(Get get)

Retrieves specific cells from a given row.

5

org.apache.hadoop.conf.Configuration getConfiguration()

Returns the Configuration object used simply simply by this particular particular instance.

6

TableName getName()

Returns the table name instance of this particular particular table.

7

HTableDescriptor getTableDescriptor()

Returns the table descriptor for this particular particular table.

8

simply simply byte[] getTableName()

Returns the name of this particular particular table.

9

void place(Put place)

Uperform this particular particular method, you can insert data into the table.

Clbum Put

This course is used to perform Put operations for a performle row. It becomesizeys to the org.apache.hadoop.hbase.csitnt package.

Constructors

S.No. Constructors and Description
1

Put(simply simply byte[] row)

Uperform this particular particular constructor, you can make a Put operation for the specified row.

2

Put(simply simply byte[] rowArray, int rowOffset, int rowLength)

Uperform this particular particular constructor, you can make a duplicate of the compalloweed-in row key to keep local.

3

Put(simply simply byte[] rowArray, int rowOffset, int rowLength, sizey ts)

Uperform this particular particular constructor, you can make a duplicate of the compalloweed-in row key to keep local.

4

Put(simply simply byte[] row, sizey ts)

Uperform this particular particular constructor, we can make a Put operation for the specified row, uperform a given timestamp.

Methods

S.No. Methods and Description
1

Put add(simply simply byte[] family, simply simply byte[] qualifier, simply simply byte[] value)

Adds the specified column and value to this particular particular Put operation.

2

Put add(simply simply byte[] family, simply simply byte[] qualifier, sizey ts, simply simply byte[] value)

Adds the specified column and value, with the specified timestamp as it is version to this particular particular Put operation.

3

Put add(simply simply byte[] family, ByteBuffer qualifier, sizey ts, ByteBuffer value)

Adds the specified column and value, with the specified timestamp as it is version to this particular particular Put operation.

4

Put add(simply simply byte[] family, ByteBuffer qualifier, sizey ts, ByteBuffer value)

Adds the specified column and value, with the specified timestamp as it is version to this particular particular Put operation.

Clbum Get

This course is used to perform Get operations on a performle row. This course becomesizeys to the org.apache.hadoop.hbase.csitnt package.

Constructor

S.No. Constructor and Description
1

Get(simply simply byte[] row)

Uperform this particular particular constructor, you can make a Get operation for the specified row.

2 Get(Get get)

Methods

S.No. Methods and Description
1

Get addColumn(simply simply byte[] family, simply simply byte[] qualifier)

Retrieves the column from the specific family with the specified qualifier.

2

Get addFamily(simply simply byte[] family)

Retrieves all columns from the specified family.

Clbum Depermite

This course is used to perform Depermite operations on a performle row. To depermite an entire row, immediateiate a Depermite object with the row to depermite. This course becomesizeys to the org.apache.hadoop.hbase.csitnt package.

Constructor

S.No. Constructor and Description
1

Depermite(simply simply byte[] row)

Creates a Depermite operation for the specified row.

2

Depermite(simply simply byte[] rowArray, int rowOffset, int rowLength)

Creates a Depermite operation for the specified row and timestamp.

3

Depermite(simply simply byte[] rowArray, int rowOffset, int rowLength, sizey ts)

Creates a Depermite operation for the specified row and timestamp.

4

Depermite(simply simply byte[] row, sizey timestamp)

Creates a Depermite operation for the specified row and timestamp.

Methods

S.No. Methods and Description
1

Depermite addColumn(simply simply byte[] family, simply simply byte[] qualifier)

Depermites the latest version of the specified column.

2

Depermite addColumns(simply simply byte[] family, simply simply byte[] qualifier, sizey timestamp)

Depermites all versions of the specified column with a timestamp less than or equal to the specified timestamp.

3

Depermite addFamily(simply simply byte[] family)

Depermites all versions of all columns of the specified family.

4

Depermite addFamily(simply simply byte[] family, sizey timestamp)

Depermites all columns of the specified family with a timestamp less than or equal to the specified timestamp.

Clbum Result

This course is used to get a performle row result of a Get or a Scan query.

Constructors

S.No. Constructors
1

Result()

Uperform this particular particular constructor, you can make an empty Result with no KeyValue payload; returns null if you call raw Cells().

Methods

S.No. Methods and Description
1

simply simply byte[] getValue(simply simply byte[] family, simply simply byte[] qualifier)

This method is used to get the latest version of the specified column.

2

simply simply byte[] getRow()

This method is used to retrieve the row key tmind wear corresponds to the row from which this particular particular Result was maked.

HBase – Create Data

Inserting Data uperform HBase Shell

This chapter demonstrates how to make data in an HBase table. To make data in an HBase table, the folloearng commands and methods are used:

  • place command,

  • add() method of Put course, and

  • place() method of HTable course.

As an example, we are going to make the folloearng table in HBase.

HBase Table

Uperform place command, you can insert rows into a table. It’s syntax is as follows:

place ’<table name>’,’row1’,’<colfamily:colname>’,’<value>’

Inserting the First Row

Let us insert the very very first row values into the emp table as shown becomelow.

hbase(main):005:0> place 'emp','1','individual data:name','raju'
0 row(s) in 0.6600 2nds
hbase(main):006:0> place 'emp','1','individual data:city','hyderabad'
0 row(s) in 0.0410 2nds
hbase(main):007:0> place 'emp','1','professional
data:styleation','manager'
0 row(s) in 0.0240 2nds
hbase(main):007:0> place 'emp','1','professional data:salary','50000'
0 row(s) in 0.0240 2nds

Insert the remaining rows uperform the place command in the extake action same way. If you insert the whole table, you will get the folloearng awayplace.

hbase(main):022:0> scan 'emp'

   ROW                        COLUMN+CELL
1 column=individual data:city, timestamp=1417524216501, value=hyderabad

1 column=individual data:name, timestamp=1417524185058, value=ramu

1 column=professional data:styleation, timestamp=1417524232601,

 value=manager
 
1 column=professional data:salary, timestamp=1417524244109, value=50000

2 column=individual data:city, timestamp=1417524574905, value=chennai

2 column=individual data:name, timestamp=1417524556125, value=ravi

2 column=professional data:styleation, timestamp=1417524592204,

 value=sr:engg
 
2 column=professional data:salary, timestamp=1417524604221, value=30000

3 column=individual data:city, timestamp=1417524681780, value=delhi

3 column=individual data:name, timestamp=1417524672067, value=rajesh

3 column=professional data:styleation, timestamp=1417524693187,

value=jr:engg
3 column=professional data:salary, timestamp=1417524702514,

value=25000 

Inserting Data Uperform Java API

You can insert data into Hbase uperform the add() method of the Put course. You can save it uperform the place() method of the HTable course. These coursees becomesizey to the org.apache.hadoop.hbase.csitnt package. Below given are the steps to make data in a Table of HBase.

Step 1:Instantiate the Configuration Clbum

The Configuration course adds HBase configuration files to it is object. You can make a configuration object uperform the make() method of the HbaseConfiguration course as shown becomelow.

Configuration conf = HbaseConfiguration.make();

Step 2:Instantiate the HTable Clbum

You have a course calimmediateed HTable, an implementation of Table in HBase. This course is used to communicate with a performle HBase table. While immediateiating this particular particular course, it accepts configuration object and table name as parameters. You can immediateiate HTable course as shown becomelow.

HTable hTable = brand new HTable(conf, tableName);

Step 3: Instantiate the PutClbum

To insert data into an HBase table, the add() method and it is variants are used. This method becomesizeys to Put, right now presently therefore immediateiate the place course. This course requires the row name you like to insert the data into, in string format. You can immediateiate the Put course as shown becomelow.

Put p = brand new Put(Bytes.toBytes("row1"));

Step 4: InsertData

The add() method of Put course is used to insert data. It requires 3 simply simply byte arrays representing column family, column qualifier (column name), and the value to become inserted, respectively. Insert data into the HBase table uperform the add() method as shown becomelow.

p.add(Bytes.toBytes("coloumn family "), Bytes.toBytes("column
name"),Bytes.toBytes("value"));

Step 5: Save the Data in Table

After inserting the required-coloureddish rows, save the modifys simply simply by adding the place instance to the place() method of HTable course as shown becomelow.

hTable.place(p); 

Step 6: Close the HTable Instance

After creating data in the HBase Table, near the HTable instance uperform the near() method as shown becomelow.

hTable.near(); 

Given becomelow is the overallll program to make data in HBase Table.

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.csitnt.HTable;
import org.apache.hadoop.hbase.csitnt.Put;
import org.apache.hadoop.hbase.util.Bytes;

public course InsertData{

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

      // Instantiating Configuration course
      Configuration config = HBaseConfiguration.make();

      // Instantiating HTable course
      HTable hTable = brand new HTable(config, "emp");

      // Instantiating Put course
      // accepts a row name.
      Put p = brand new Put(Bytes.toBytes("row1")); 

      // adding values uperform add() method
      // accepts column family name, qualifier/row name ,value
      p.add(Bytes.toBytes("individual"),
      Bytes.toBytes("name"),Bytes.toBytes("raju"));

      p.add(Bytes.toBytes("individual"),
      Bytes.toBytes("city"),Bytes.toBytes("hyderabad"));

      p.add(Bytes.toBytes("professional"),Bytes.toBytes("styleation"),
      Bytes.toBytes("manager"));

      p.add(Bytes.toBytes("professional"),Bytes.toBytes("salary"),
      Bytes.toBytes("50000"));
      
      // Saving the place Instance to the HTable.
      hTable.place(p);
      System.away.println("data inserted");
      
      // cloperform HTable
      hTable.near();
   }
}

Compile and execute the above program as shown becomelow.

$javac InsertData.java
$java InsertData

The folloearng ought to become the awayplace:

data inserted

HBase – Update Data

Updating Data uperform HBase Shell

You can update an existing cell value uperform the place command. To do so, simply follow the extake action same syntax and mention your own brand new value as shown becomelow.

place ‘table name’,’row ’,'Column family:column name',’brand new value’

The brand newly given value replaces the existing value, updating the row.

Example

Suppose right now presently there is a table in HBase calimmediateed emp with the folloearng data.

hbase(main):003:0> scan 'emp'
 ROW              COLUMN + CELL
row1 column = individual:name, timestamp = 1418051555, value = raju
row1 column = individual:city, timestamp = 1418275907, value = Hyderabad
row1 column = professional:styleation, timestamp = 14180555,value = manager
row1 column = professional:salary, timestamp = 1418035791555,value = 50000
1 row(s) in 0.0100 2nds

The folloearng command will update the city value of the employee named ‘Raju’ to Delhi.

hbase(main):002:0> place 'emp','row1','individual:city','Delhi'
0 row(s) in 0.0400 2nds

The updated table looks as follows where you can observe the city of Raju has becomeen modifyd to ‘Delhi’.

hbase(main):003:0> scan 'emp'
  ROW          COLUMN + CELL
row1 column = individual:name, timestamp = 1418035791555, value = raju
row1 column = individual:city, timestamp = 1418274645907, value = Delhi
row1 column = professional:styleation, timestamp = 141857555,value = manager
row1 column = professional:salary, timestamp = 1418039555, value = 50000
1 row(s) in 0.0100 2nds

Updating Data Uperform Java API

You can update the data in a particular cell uperform the place() method. Follow the steps given becomelow to update an existing cell value of a table.

Step 1: Instantiate the Configuration Clbum

Configuration course adds HBase configuration files to it is object. You can make a configuration object uperform the make() method of the HbaseConfiguration course as shown becomelow.

Configuration conf = HbaseConfiguration.make();

Step 2: Instantiate the HTable Clbum

You have a course calimmediateed HTable, an implementation of Table in HBase. This course is used to communicate with a performle HBase table. While immediateiating this particular particular course, it accepts the configuration object and the table name as parameters. You can immediateiate the HTable course as shown becomelow.

HTable hTable = brand new HTable(conf, tableName);

Step 3: Instantiate the Put Clbum

To insert data into HBase Table, the add() method and it is variants are used. This method becomesizeys to Put, right now presently therefore immediateiate the place course. This course requires the row name you like to insert the data into, in string format. You can immediateiate the Put course as shown becomelow.

Put p = brand new Put(Bytes.toBytes("row1"));

Step 4: Update an Existing Cell

The add() method of Put course is used to insert data. It requires 3 simply simply byte arrays representing column family, column qualifier (column name), and the value to become inserted, respectively. Insert data into HBase table uperform the add() method as shown becomelow.

p.add(Bytes.toBytes("coloumn family "), Bytes.toBytes("column
name"),Bytes.toBytes("value"));
p.add(Bytes.toBytes("individual"),
Bytes.toBytes("city"),Bytes.toBytes("Delih"));

Step 5: Save the Data in Table

After inserting the required-coloureddish rows, save the modifys simply simply by adding the place instance
to the place() method of the HTable course as shown becomelow.

hTable.place(p); 

Step 6: Close HTable Instance

After creating data in HBase Table, near the HTable instance uperform the near() method as shown becomelow.

hTable.near();

Given becomelow is the overallll program to update data in a particular table.

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.csitnt.HTable;
import org.apache.hadoop.hbase.csitnt.Put;
import org.apache.hadoop.hbase.util.Bytes;

public course UpdateData{

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

      // Instantiating Configuration course
      Configuration config = HBaseConfiguration.make();

      // Instantiating HTable course
      HTable hTable = brand new HTable(config, "emp");

      // Instantiating Put course
      //accepts a row name
      Put p = brand new Put(Bytes.toBytes("row1"));

      // Updating a cell value
      p.add(Bytes.toBytes("individual"),
      Bytes.toBytes("city"),Bytes.toBytes("Delih"));

      // Saving the place Instance to the HTable.
      hTable.place(p);
      System.away.println("data Updated");

      // cloperform HTable
      hTable.near();
   }
}

Compile and execute the above program as shown becomelow.

$javac UpdateData.java
$java UpdateData

The folloearng ought to become the awayplace:

data Updated

HBase – Read Data

Reading Data uperform HBase Shell

The get command and the get() method of HTable course are used to read data from a table in HBase. Uperform get command, you can get a performle row of data at a time. It’s syntax is as follows:

get ’<table name>’,’row1’

Example

The folloearng example shows how to use the get command. Let us scan the very very first row of the emp table.

hbase(main):012:0> get 'emp', '1'

   COLUMN                     CELL
   
individual : city timestamp = 1417521848375, value = hyderabad

individual : name timestamp = 1417521785385, value = ramu

professional: styleation timestamp = 1417521885277, value = manager

professional: salary timestamp = 1417521903862, value = 50000

4 row(s) in 0.0270 2nds

Reading a Specific Column

Given becomelow is the syntax to read a specific column uperform the get method.

hbase> get 'table name', ‘rowid’, {COLUMN ⇒ ‘column family:column name ’}

Example

Given becomelow is the example to read a specific column in HBase table.

hbase(main):015:0> get 'emp', 'row1', {COLUMN ⇒ 'individual:name'}
  COLUMN                CELL  
individual:name timestamp = 1418035791555, value = raju
1 row(s) in 0.0080 2nds

Reading Data Uperform Java API

To read data from an HBase table, use the get() method of the HTable course. This method requires an instance of the Get course. Follow the steps given becomelow to retrieve data from the HBase table.

Step 1: Instantiate the Configuration Clbum

Configuration course adds HBase configuration files to it is object. You can make a configuration object uperform the make() method of the HbaseConfiguration course as shown becomelow.

Configuration conf = HbaseConfiguration.make();

Step 2: Instantiate the HTable Clbum

You have a course calimmediateed HTable, an implementation of Table in HBase. This course is used to communicate with a performle HBase table. While immediateiating this particular particular course, it accepts the configuration object and the table name as parameters. You can immediateiate the HTable course as shown becomelow.

HTable hTable = brand new HTable(conf, tableName);

Step 3: Instantiate the Get Clbum

You can retrieve data from the HBase table uperform the get() method of the HTable course. This method extrtake actions a cell from a given row. It requires a Get course object as parameter. Create it as shown becomelow.

Get get = brand new Get(toBytes("row1"));

Step 4: Read the Data

While retrieving data, you can get a performle row simply simply by id, or get a set of rows simply simply by a set of row ids, or scan an entire table or a subset of rows.

You can retrieve an HBase table data uperform the add method variants in Get course.

To get a specific column from a specific column family, use the folloearng method.

get.addFamily(individual) 

To get all the columns from a specific column family, use the folloearng method.

get.addColumn(individual, name) 

Step 5: Get the Result

Get the result simply simply by pasperform your own Get course instance to the get method of the HTable course. This method returns the Result course object, which holds the requested result. Given becomelow is the usage of get() method.

Result result = table.get(g);  

Step 6: Reading Values from the Result Instance

The Result course provides the getValue() method to read the values from it is instance. Use it as shown becomelow to read the values from the Result instance.

simply simply byte [] value = result.getValue(Bytes.toBytes("individual"),Bytes.toBytes("name"));
simply simply byte [] value1 = result.getValue(Bytes.toBytes("individual"),Bytes.toBytes("city"));

Given becomelow is the overallll program to read values from an HBase table.

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.csitnt.Get;
import org.apache.hadoop.hbase.csitnt.HTable;
import org.apache.hadoop.hbase.csitnt.Result;
import org.apache.hadoop.hbase.util.Bytes;

public course RetriveData{

   public static void main(String[] args) throws IOException, Exception{
   
      // Instantiating Configuration course
      Configuration config = HBaseConfiguration.make();

      // Instantiating HTable course
      HTable table = brand new HTable(config, "emp");

      // Instantiating Get course
      Get g = brand new Get(Bytes.toBytes("row1"));

      // Reading the data
      Result result = table.get(g);

      // Reading values from Result course object
      simply simply byte [] value = result.getValue(Bytes.toBytes("individual"),Bytes.toBytes("name"));

      simply simply byte [] value1 = result.getValue(Bytes.toBytes("individual"),Bytes.toBytes("city"));

      // Printing the values
      String name = Bytes.toString(value);
      String city = Bytes.toString(value1);
      
      System.away.println("name: " + name + " city: " + city);
   }
}

Compile and execute the above program as shown becomelow.

$javac RetriveData.java
$java RetriveData

The folloearng ought to become the awayplace:

name: Raju city: Delhi

HBase – Depermite Data

Depermiting a Specific Cell in a Table

Uperform the depermite command, you can depermite a specific cell in a table. The syntax of depermite command is as follows:

depermite ‘<table name>’, ‘<row>’, ‘<column name >’, ‘<time stamp>’

Example

Here is an example to depermite a specific cell. Here we are depermiting the salary.

hbase(main):006:0> depermite 'emp', '1', 'individual data:city',
1417521848375
0 row(s) in 0.0060 2nds

Depermiting All Cells in a Table

Uperform the “depermiteall” command, you can depermite all the cells in a row. Given becomelow is the syntax of depermiteall command.

depermiteall ‘<table name>’, ‘<row>’,

Example

Here is an example of “depermiteall” command, where we are depermiting all the cells of row1 of emp table.

hbase(main):007:0> depermiteall 'emp','1'
0 row(s) in 0.0240 2nds

Verify the table uperform the scan command. A snapshot of the table after depermiting the table is given becomelow.

hbase(main):022:0> scan 'emp'

ROW                  COLUMN + CELL

2 column = individual data:city, timestamp = 1417524574905, value = chennai 

2 column = individual data:name, timestamp = 1417524556125, value = ravi

2 column = professional data:styleation, timestamp = 1417524204, value = sr:engg

2 column = professional data:salary, timestamp = 1417524604221, value = 30000

3 column = individual data:city, timestamp = 1417524681780, value = delhi

3 column = individual data:name, timestamp = 1417524672067, value = rajesh
 
3 column = professional data:styleation, timestamp = 1417523187, value = jr:engg

3 column = professional data:salary, timestamp = 1417524702514, value = 25000

Depermiting Data Uperform Java API

You can depermite data from an HBase table uperform the depermite() method of the HTable course. Follow the steps given becomelow to depermite data from a table.

Step 1: Instantiate the Configuration Clbum

Configuration course adds HBase configuration files to it is object. You can make a configuration object uperform the make() method of the the HbaseConfiguration course as shown becomelow.

Configuration conf = HbaseConfiguration.make();

Step 2: Instantiate the HTable Clbum

You have a course calimmediateed HTable, an implementation of Table in HBase. This course is used to communicate with a performle HBase table. While immediateiating this particular particular course, it accepts the configuration object and the table name as parameters. You can immediateiate the HTable course as shown becomelow.

HTable hTable = brand new HTable(conf, tableName); 

Step 3: Instantiate the Depermite Clbum

Instantiate the Depermite course simply simply by pasperform the rowid of the row tmind wear is to become depermited, in simply simply byte array format. You can furthermore compallowe timestamp and Rowlock to this particular particular constructor.

Depermite depermite = brand new Depermite(toBytes("row1"));

Step 4: Select the Data to become Depermited

You can depermite the data uperform the depermite methods of the Depermite course. This course has various depermite methods. Choose the columns or column famisit is to become depermited uperform those methods. Take a look at the folloearng examples tmind wear show the usage of Depermite course methods.

depermite.depermiteColumn(Bytes.toBytes("individual"), Bytes.toBytes("name"));
depermite.depermiteFamily(Bytes.toBytes("professional"));

Step 5: Depermite the Data

Depermite the selected data simply simply by pasperform the depermite instance to the depermite() method of the HTable course as shown becomelow.

table.depermite(depermite); 

Step 6: Close the HTableInstance

After depermiting the data, near the HTable Instance.

table.near();

Given becomelow is the overallll program to depermite data from the HBase table.

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.csitnt.Depermite;
import org.apache.hadoop.hbase.csitnt.HTable;
import org.apache.hadoop.hbase.util.Bytes;

public course DepermiteData {

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

      // Instantiating Configuration course
      Configuration conf = HBaseConfiguration.make();

      // Instantiating HTable course
      HTable table = brand new HTable(conf, "employee");

      // Instantiating Depermite course
      Depermite depermite = brand new Depermite(Bytes.toBytes("row1"));
      depermite.depermiteColumn(Bytes.toBytes("individual"), Bytes.toBytes("name"));
      depermite.depermiteFamily(Bytes.toBytes("professional"));

      // depermiting the data
      table.depermite(depermite);

      // cloperform the HTable object
      table.near();
      System.away.println("data depermited.....");
   }
}

Compile and execute the above program as shown becomelow.

$javac Depermitedata.java
$java DepermiteData

The folloearng ought to become the awayplace:

data depermited

HBase – Scan

Scaning uperform HBase Shell

The scan command is used to watch the data in HTable. Uperform the scan command, you can get the table data. It’s syntax is as follows:

scan ‘<table name>’ 

Example

The folloearng example shows how to read data from a table uperform the scan command. Here we are reading the emp table.

hbase(main):010:0> scan 'emp'

ROW                           COLUMN + CELL

1 column = individual data:city, timestamp = 1417521848375, value = hyderabad
 
1 column = individual data:name, timestamp = 1417521785385, value = ramu

1 column = professional data:styleation, timestamp = 1417585277,value = manager

1 column = professional data:salary, timestamp = 1417521903862, value = 50000

1 row(s) in 0.0370 2nds

Scanning Uperform Java API

The overallll program to scan the entire table data uperform java API is as follows.

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.util.Bytes;

import org.apache.hadoop.hbase.csitnt.HTable;
import org.apache.hadoop.hbase.csitnt.Result;
import org.apache.hadoop.hbase.csitnt.ResultScanner;
import org.apache.hadoop.hbase.csitnt.Scan;


public course ScanTable{

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

      // Instantiating Configuration course
      Configuration config = HBaseConfiguration.make();

      // Instantiating HTable course
      HTable table = brand new HTable(config, "emp");

      // Instantiating the Scan course
      Scan scan = brand new Scan();

      // Scanning the required-coloureddish columns
      scan.addColumn(Bytes.toBytes("individual"), Bytes.toBytes("name"));
      scan.addColumn(Bytes.toBytes("individual"), Bytes.toBytes("city"));

      // Getting the scan result
      ResultScanner scanner = table.getScanner(scan);

      // Reading values from scan result
      for (Result result = scanner.next(); result != null; result = Scanner.next())

      System.away.println("Found row : " + result);
      //cloperform the scanner
      scanner.near();
   }
}

Compile and execute the above program as shown becomelow.

$javac ScanTable.java
$java ScanTable 

The folloearng ought to become the awayplace:

Found row :
keyvalues={row1/individual:city/1418275612888/Put/vlen=5/mvcc=0,
row1/individual:name/1418035791555/Put/vlen=4/mvcc=0}

HBase – Count & Toperatecate

count

You can count the numbecomer of rows of a table uperform the count command. It’s syntax is as follows:

count ‘<table name>’ 

After depermiting the very very first row, emp table will have 2 rows. Verify it as shown becomelow.

hbase(main):023:0> count 'emp'
2 row(s) in 0.090 2nds
⇒ 2 

toperatecate

This command disables falls and red-colouremakes a table. The syntax of toperatecate is as follows:

hbase> toperatecate 'table name'

Example

Given becomelow is the example of toperatecate command. Here we have toperatecated the emp table.

hbase(main):011:0> toperatecate 'emp'
Toperatecating 'one' table (it may get a while):
   - Disabling table...
   - Toperatecating table...
   0 row(s) in 1.5950 2nds

After toperatecating the table, use the scan command to verify. You will get a table with zero rows.

hbase(main):017:0> scan ‘emp’
ROW                  COLUMN + CELL
0 row(s) in 0.3110 2nds

HBase – Security

We can grant and revoke permissions to users in HBase. There are three commands for security purpose: grant, revoke, and user_permission.

grant

The grant command grants specific rights such as read, write, execute, and admin on a table to a specific user. The syntax of grant command is as follows:

hbase> grant <user> <permissions> [<table> [<column family> [<column; qualifier>]]

We can grant zero or more privileges to a user from the set of RWXCA, where

  • R – represents read privilege.
  • W – represents write privilege.
  • X – represents execute privilege.
  • C – represents make privilege.
  • A – represents admin privilege.

Given becomelow is an example tmind wear grants all privileges to a user named ‘Tutorialspoint’.

hbase(main):018:0> grant 'Tutorialspoint', 'RWXCA'

revoke

The revoke command is used to revoke a user's access rights of a table. It’s syntax is as follows:

hbase> revoke <user>

The folloearng code revokes all the permissions from the user named ‘Tutorialspoint’.

hbase(main):006:0> revoke 'Tutorialspoint'

user_permission

This command is used to list all the permissions for a particular table. The
syntax of user_permission is as follows:

hbase>user_permission ‘tablename’

The folloearng code lists all the user permissions of ‘emp’ table.

hbase(main):013:0> user_permission 'emp'
SHARE
Previous articleSAP Solman
Next articleSelf

NO COMMENTS

LEAVE A REPLY