HBase

0
15

HBase – Oversee

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

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

Limitations of Hadoop

Hadoop can perform only batch procesperform, and data will become accessed only in a sequential manner. Thead use means one has to oceanrch the entire dataset workually for the easyst 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 unit of time (random access).

Hadoop Random Access Databases

Applications such as HBase, Casgood sandra, couchDB, Dynamo, and MongoDB are some of the databases thead use store huge amounts of data and access the data in a random manner.

Whead use 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 thead use is similar to Google’s huge table styleed to provide quick random access to huge amounts of structureddish coloureddish coloureddish coloured data. It leverages the fault tolerance provided simply by the Hadoop File System (HDFS).

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

One can store the data in HDFS either immediately or through HBase. Data consumer reads/accesses the data in HDFS randomly uperform HBase. HBase sit down’s 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 supslot quick individual record lookups. HBase provides quick lookups for huger tables.
It provides high latency batch procesperform; no concept of batch procesperform. It provides low latency access to performle lines 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 quicker lookups.

Storage Mechanism in HBase

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

  • Table is a collection of lines.
  • Row is a collection of column famiare locateds.
  • 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 thead use store data tables as sections of columns of data, instead than as lines of data. Shortly, they will have column famiare locateds.

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

The following image shows column famiare locateds 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; degoods only column famiare locateds. An RDBMS is governed simply by it’s schema, which describecomes the whole structure of tables.
It is built for wide tables. HBase is horizontally scalable. It is thin and built for small tables. Hard to range.
No transworkions are presently generally there in HBase. RDBMS is transworkional.
It has de-normalized data. It will have normalized data.
It is good for semi-structureddish coloureddish coloureddish coloured as well as structureddish coloureddish coloureddish coloured data. It is good for structureddish coloureddish coloureddish coloured data.

Features of HBase

  • HBase is collectionarly scalable.
  • It has automatic failure supslot.
  • It provides consistent read and writes.
  • It integrates with Hadoop, both as a source and a destination.
  • It has easy java API for care locatednt.
  • It provides data replication across 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 modeintroduced after Google's Bigtable. Bigtable works up on Google File System, likewise Apache HBase works on top of Hadoop and HDFS.

Applications of HBase

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

HBase History

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

HBase – Architecture

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

Note: The term ‘store’ is used for regions to exordinary the storage structure.

HBase Architecture

HBase has 3 major components: the care locatednt library, a master server, and region servers. Region servers can become added or removed as per requirement.

MasterServer

The master server –

  • Assigns regions to the region servers and takes the help of Apache ZooKeeper for this particular particular task.

  • Handles load balancing of the regions across region servers. It unloads the hectic servers and shifts the regions to less occupied servers.

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

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

Regions

Regions are absolutely nothing but tables thead use are split up and spread across the region servers.

Region server

The region servers have regions thead use –

  • Communicate with the care locatednt and handle data-related operations.
  • Handle read and write requests for all the regions below it.
  • Decide the dimension of the region simply by following the region dimension thresholds.

When we take a deeper look into the region server, it contain regions and stores as shown becomelow:

Regional Server

The store contains memory store and HFiles. Memstore is simply like a cache memory. Anything thead use is entereddish coloureddish coloureddish coloured into the HBase is storeddish coloureddish coloureddish coloured here preliminaryly. Later, the data is transferreddish coloureddish coloureddish coloured and saved in Hfiles as blocks and the memstore is flushed.

Zookeeper

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

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

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

  • Care locatednts communicate with region servers via zookeeper.

  • In pseudo and standasingle modes, HBase it’self will take care of zookeeper.

HBase – Installation

This chapter exordinarys how HBase is withinstalintroduced and preliminaryly configureddish coloureddish coloureddish coloured. Java and
Hadoop are requireddish coloureddish coloureddish coloured 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 generate a separate user for Hadoop to isolate the Hadoop file system from the Unix file system. Follow the steps given becomelow to generate 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 kind the following commands to generate a user.

$ su
moveword:
# useradd hadoop
# movewd hadoop
New movewd:
Rekind brand new movewd

SSH Setup and Key Generation

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

The following 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 prerequisit downe 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 everything works good, it will give you the following out generally thereplace.

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

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

Step 1

Download java (JDK <lacheck version> – X64.tar.gz) simply by visit downing the following 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 extrwork the jdk-7u71-linux-x64.gz file uperform the following 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 generate java available to all the users, you have to move it to the location “/usr/local/”. Open underlying and kind the following commands.

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

Step 4

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

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

Now apply all the modifys into the current running system.

$ source ~/.bashrc

Step 5

Use the following 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 exordinaryed 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 everything works good, it will give you the following out generally thereplace.

Hadoop 2.6.0
Compiintroduced simply by jenkins on 2014-11-13T21:10Z
Compiintroduced with protoc 2.5.0
From source with checksum 18e43357c8f927c0695f1e9522859d6a
This command was run 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 extrwork hadoop-2.6.0 from Apache Softbattlee Foundation uperform the following commands.

$ su
moveword:
# 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 requireddish coloureddish coloureddish coloured mode. Here, we are demonstrating HBase functionalitie ups in pseudo distributed mode, presently generally therefore install Hadoop in pseudo distributed mode.

The following steps are used for installing Hadoop 2.4.1.

Step 1 – Setting up Hadoop

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

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

Now apply all the modifys into the current running 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 generate modifys in those configuration files according to your own Hadoop infrastructure.

$ cd $HADOOP_HOME/etc/hadoop

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

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

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

core-sit downe.xml

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

Open core-sit downe.xml and add the following propertie ups in becometween the <configuration> and </configuration> tags.

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

hdfs-sit downe.xml

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

Let us assume the following data.

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

namenode rout generally theree = //home/hadoop/hadoopinfra/hdfs/namenode
(hadoopinfra/hdfs/datanode is the immediateory generated simply by hdfs file system.)

datanode rout generally theree = //home/hadoop/hadoopinfra/hdfs/datanode

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

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

Note: In the above file, all the house values are user-degoodd and you can generate modifys according to your own Hadoop infrastructure.

yarn-sit downe.xml

This file is used to configure yarn into Hadoop. Open the yarn-sit downe.xml file and add the following house in becometween the <configuration$gt;, </configuration$gt; tags in this particular particular file.

<configuration>
   <house>
      <name>yarn.nodemanager.aux-services</name>
      <value>mapreddish coloureddish coloureddish coloureduce_shuffle</value>
   </house>
</configuration>

mapreddish coloureddish coloureddish coloured-sit downe.xml

This file is used to specify which MapReduce framework we are uperform. By default, Hadoop contains a template of yarn-sit downe.xml. First of all, it is requireddish coloureddish coloureddish coloured to copy the file from mapreddish coloureddish coloureddish coloured-sit downe.xml.template to mapreddish coloureddish coloureddish coloured-sit downe.xml file uperform the following command.

$ cp mapreddish coloureddish coloureddish coloured-sit downe.xml.template mapreddish coloureddish coloureddish coloured-sit downe.xml

Open mapreddish coloureddish coloureddish coloured-sit downe.xml file and add the following propertie ups in becometween the <configuration> and </configuration> tags.

<configuration>
   <house>
      <name>mapreddish coloureddish coloureddish coloureduce.framework.name</name>
      <value>yarn</value>
   </house>
</configuration>

Verifying Hadoop Installation

The following 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 following command is used to start dfs. Executing this particular particular command will start your own Hadoop file system.

$ start-dfs.sh

The expected out generally thereplace 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.out generally there
localhost: starting datanode, logging to /home/hadoop/hadoop-
2.4.1/logs/hadoop-hadoop-datanode-localhost.out generally there
Starting 2ndary namenodes [0.0.0.0]

Step 3 – Verifying Yarn Script

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

$ start-yarn.sh

The expected out generally thereplace is as follows.

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

Step 4 – Accesperform Hadoop on Blineser

The default slot numbecomer to access Hadoop is 50070. Use the following url to get Hadoop services on your own blineser.

http://localhost:50070

Hadoop on Blineser

Step 5 – Verify all Applications of Cluster

The default slot numbecomer to access all the applications of cluster is 8088. Use the following url to visit down this particular particular service.

http://localhost:8088/

Hadoop Applicatin Cluster

Installing HBase

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

Installing HBase in Standasingle Mode

Download the lacheck stable version of HBase form /index.php?s=httpwwwinterior-dsgncomapachehbasestable uperform “wget” command, and extrwork it uperform the tar “zxvf” command. See the following command.

$cd usr/local/
$wget /index.php?s=httpwwwinterior-dsgncomapachehbasestablehbase-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
$moveword: enter your own moveword here
mv hbase-0.99.1/* Hbase/

Configuring HBase in Standasingle Mode

Before proceeding with HBase, you have to edit the following 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 rout generally theree 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.

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

hbase-sit downe.xml

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

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

Inpart the hbase-sit downe.xml file, you will find the <configuration> and
</configuration> tags. Within all of them, set the HBase immediateory below the house
key with the name “hbase.underlyingdir” as shown becomelow.

<configuration>
   //Here you have to set the rout generally theree where you like HBase to store it's files.
   <house>
      <name>hbase.underlyingdir</name>
      <value>file:/home/hadoop/HBase/HFiles</value>
   </house>
	
   //Here you have to set the rout generally theree where you like HBase to store it's built in zookeeper  files.
   <house>
      <name>hbase.zookeeper.house.dataDir</name>
      <value>/home/hadoop/zookeeper</value>
   </house>
</configuration>

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

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

If everything goes well, when you try out generally there to run HBase start script, it will prompt you a message saying thead use HBase has started.

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

Installing HBase in Pseudo-Distributed Mode

Let us now check how HBase is withinstalintroduced 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 generate sure they are running. Stop HBase if it is running.

hbase-sit downe.xml

Edit hbase-sit downe.xml file to add the following propertie ups.

<house>
   <name>hbase.cluster.distributed</name>
   <value>true</value>
</house>

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

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

Starting HBase

After configuration is over, blinese to HBase home folder and start HBase uperform the following command.

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

Note: Before starting HBase, generate sure Hadoop is running.

Checruler the HBase Directory in HDFS

HBase generates it’s immediateory in HDFS. To see the generated immediateory, blinese to Hadoop bin and kind the following command.

$ ./bin/hadoop fs -ls /hbase

If everything goes well, it will give you the following out generally thereplace.

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 following command to start it.

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

To eliminate a backup master, you need it’s process id, which will become storeddish coloureddish coloureddish coloured in a file named “/tmp/hbase-USER-X-master.pid.” you can eliminate the backup master uperform the following command.

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

Starting and Stopping RegionServers

You can run multiple region servers from a performle system uperform the following command.

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

To stop a region server, use the following command.

$ .bin/local-regionservers.sh stop 3

 

Starting HBaseShell

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

Start Hadoop File System

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

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

Start HBase

Blinese 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 region server as shown becomelow.

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

Start HBase Shell

You can start HBase shell uperform the following 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 supsloted 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, kind the following url in the blineser.

http://localhost:60010

This withinterface lists your own currently running 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 classrout generally theree for those libraries.

Setting the Classrout generally theree

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

$ gedit ~/.bashrc

Set classrout generally theree for HBase libraries (lib folder in HBase) in it as shown becomelow.

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

This is to prworkuallyt the “class not found” other thanion while accesperform the HBase uperform java API.

HBase – Shell

This chapter exordinarys how to start HBase interworkive shell thead use comes adurationy with HBase.

HBase Shell

HBase contains a shell uperform which you can communicate with HBase. HBase uses the Hadoop File System to store it’s data. It will have a master server and region servers. The data storage will become in the form of regions (tables). These regions will become split up and storeddish coloureddish coloureddish coloured in region servers.

The master server manages these region servers and all these tasks take place on HDFS. Given becomelow are some of the commands supsloted 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 about generally there the user.

Data Definition Language

These are the commands thead use operate on the tables in HBase.

  • generate – Creates a table.

  • list – Lists all the tables in HBase.

  • disable – Disables a table.

  • is_disabintroduced – Verifies whether a table is disabintroduced.

  • enable – Enables a table.

  • is_enabintroduced – Verifies whether a table is enabintroduced.

  • 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 matching the ‘regex’ given in the command.

  • Java Admin API – Prior to all the above commands, Java provides an Admin API to achieve DDL functionalitie ups through programming. Under org.apache.hadoop.hbase.care locatednt package, HBaseAdmin and
    HTableDescriptor are the 2 imslotant classes in this particular particular package thead use provide DDL functionalitie ups.

Data Manipulation Language

  • place – Puts a cellular value at a specified column in a specified line in a
    particular table.

  • get – Fetches the contents of line or a cellular.

  • depermite – Depermites a cellular value in a table.

  • depermiteall – Depermites all the cellulars in a given line.

  • scan – Scans and returns the table data.

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

  • truncate – Disables, falls, and reddish colouregenerates a specified table.

  • Java care locatednt API – Prior to all the above commands, Java provides a care locatednt API to achieve DML functionalitie ups, CRUD (Create Retrieve Update Depermite) operations and more through programming, below org.apache.hadoop.hbase.care locatednt package. HTable Put and Get are the imslotant classes 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 interworkive shell uperform “hbase shell” command as shown becomelow.

./bin/hbase shell

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

HBase Shell; enter 'help<RETURN>' for list of supsloted 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 interworkive shell command at any kind of moment, kind 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 kind this particular particular command, it gives you the following out generally thereplace.

hbase(main):001:0> list
TABLE

HBase – General Commands

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

status

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

hbase(main):009:0> status

If you execute this particular particular command, it returns the following out generally thereplace.

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 following out generally thereplace.

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

table_help

This command guides you whead use 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 out generally thereplace of this particular particular command.

hbase(main):002:0> table_help
Help for table-reference commands.
You can either generate a table via 'generate' 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 generate a table and keep around a reference to
it via:
 hbase> t = generate '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 composed in java, presently generally therefore it provides java API to communicate with HBase. Java API is the fascheck way to communicate with HBase. Given becomelow is the referenced java Admin API thead use covers the tasks used to manage tables.

Class HBaseAdmin

HBaseAdmin is a class representing the Admin. This class becomedurationys to the org.apache.hadoop.hbase.care locatednt package. Uperform this particular particular class, 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 generateTable(HTableDescriptor desc)

Creates a brand new table.

2

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

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

3

void depermiteColumn(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.

Class Descriptor

This class contains the details about generally there an HBase table such as:

  • the descriptors of all the column famiare locateds,
  • if the table is a catalog table,
  • if the table is read only,
  • the maximum dimension of the mem store,
  • when the region split ought to occur,
  • co-processors associated 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 generate a table uperform the generate command, here you must specify the table name and the Column Family name. The syntax to generate a table in HBase shell is shown becomelow.

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

Example

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

Row key private data professional data

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

hbase(main):002:0> generate 'emp', 'private data', ’professional data’

And it will give you the following out generally thereplace.

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

Verification

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

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

Creating a Table Uperform java API

You can generate a table in HBase uperform the generateTable() method of HBaseAdmin class. This class becomedurationys to the org.apache.hadoop.hbase.care locatednt package. Given becomelow are the steps to generate a table in HBase uperform java API.

Step1: Instantiate HBaseAdmin

This class requires the Configuration object as a parameter, presently generally therefore preliminaryly quickiate the Configuration class and move this particular particular instance to HBaseAdmin.

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

Step2: Create TableDescriptor

HTableDescriptor is a class thead use becomedurationys to the org.apache.hadoop.hbase class. This class is like a container of table names and column famiare locateds.

//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 generateTable() method of HBaseAdmin class, you can execute the generated table in Admin mode.

admin.generateTable(table);

Given becomelow is the comppermite program to generate a table via admin.

imslot java.io.IOException;

imslot org.apache.hadoop.hbase.HBaseConfiguration;
imslot org.apache.hadoop.hbase.HColumnDescriptor;
imslot org.apache.hadoop.hbase.HTableDescriptor;
imslot org.apache.hadoop.hbase.care locatednt.HBaseAdmin;
imslot org.apache.hadoop.hbase.TableName;

imslot org.apache.hadoop.conf.Configuration;

public class CreateTable {
      
   public static void main(String[] args) thlines IOException {

      // Instantiating configuration class
      Configuration con = HBaseConfiguration.generate();

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

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

      // Adding column famiare locateds to table descriptor
      tableDescriptor.addFamily(brand new HColumnDescriptor("private"));
      tableDescriptor.addFamily(brand new HColumnDescriptor("professional"));

      // Execute the table through admin
      admin.generateTable(tableDescriptor);
      System.out generally there.println(" Table generated ");
   }
}

Compile and execute the above program as shown becomelow.

$javac CreateTable.java
$java CreateTable

The following ought to become the out generally thereplace:

Table generated

HBase – Listing Table

Listing a Table uperform HBase Shell

list is the command thead use 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 kind 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 calintroduced listTables() in the class 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.generate();

//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 class. 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.

imslot java.io.IOException;

imslot org.apache.hadoop.conf.Configuration;

imslot org.apache.hadoop.hbase.HBaseConfiguration;
imslot org.apache.hadoop.hbase.HTableDescriptor;
imslot org.apache.hadoop.hbase.MasterNotRunningException;
imslot org.apache.hadoop.hbase.care locatednt.HBaseAdmin;

public class ListTables {

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

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

      // Instantiating HBaseAdmin class
      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.out generally there.println(tableDescriptor[i].getNameAsString());
      }
   
   }
}

Compile and execute the above program as shown becomelow.

$javac ListTables.java
$java ListTables

The following ought to become the out generally thereplace:

User
emp

HBase – Disabling a Table

Disabling a Table uperform HBase Shell

To depermite a table or modify it’s settings, you need to 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 thead use shows how to disable a table.

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

Verification

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

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

is_disabintroduced

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

hbase> is_disabintroduced 'table name'

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

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

disable_all

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

hbase> disable_all 'r.*'

Suppose presently generally there are 5 tables in HBase, namely raja, rajani, rajendra, rajesh, and
raju. The following 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 disabintroduced

Disable a Table Uperform Java API

To verify whether a table is disabintroduced, isTableDisabintroduced() method is used and to disable a table, disableTable() method is used. These methods becomedurationy to the HBaseAdmin class. Follow the steps given becomelow to disable a table.

Step 1

Instantiate HBaseAdmin class as shown becomelow.

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

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

Step 2

Verify whether the table is disabintroduced uperform isTableDisabintroduced() method as shown becomelow.

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

Step 3

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

if(!b){
   admin.disableTable("emp");
   System.out generally there.println("Table disabintroduced");
}

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

imslot java.io.IOException;

imslot org.apache.hadoop.conf.Configuration;

imslot org.apache.hadoop.hbase.HBaseConfiguration;
imslot org.apache.hadoop.hbase.MasterNotRunningException;
imslot org.apache.hadoop.hbase.care locatednt.HBaseAdmin;

public class DisableTable{

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

      // Instantiating configuration class
      Configuration conf = HBaseConfiguration.generate();
 
      // Instantiating HBaseAdmin class
      HBaseAdmin admin = brand new HBaseAdmin(conf);

      // Verifying weather conditions the table is disabintroduced
      Boolean bool = admin.isTableDisabintroduced("emp");
      System.out generally there.println(bool);

      // Disabling the table uperform HBaseAdmin object
      if(!bool){
         admin.disableTable("emp");
         System.out generally there.println("Table disabintroduced");
      }
   }
}

Compile and execute the above program as shown becomelow.

$javac DisableTable.java
$java DsiableTable

The following ought to become the out generally thereplace:

false
Table disabintroduced

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 line(s) in 0.4580 2nds

Verification

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

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

   ROW                        COLUMN + CELL

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

1 column = private 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 = private data:city, timestamp = 1417524574905, value = chennai

2 column = private 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 = private data:city, timestamp = 1417524681780, value = delhi

3 column = private 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 line(s) in 0.0400 2nds

is_enabintroduced

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

hbase> is_enabintroduced 'table name'

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

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

Enable a Table Uperform Java API

To verify whether a table is enabintroduced, isTableEnabintroduced() method is used; and to enable a table, enableTable() method is used. These methods becomedurationy to HBaseAdmin class. Follow the steps given becomelow to enable a table.

Step1

Instantiate HBaseAdmin class as shown becomelow.

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

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

Step 2

Verify whether the table is enabintroduced uperform isTableEnabintroduced() method as shown becomelow.

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

Step 3

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

if(!bool){
   admin.enableTable("emp");
   System.out generally there.println("Table enabintroduced");
}

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

imslot java.io.IOException;

imslot org.apache.hadoop.conf.Configuration;

imslot org.apache.hadoop.hbase.HBaseConfiguration;
imslot org.apache.hadoop.hbase.MasterNotRunningException;
imslot org.apache.hadoop.hbase.care locatednt.HBaseAdmin;

public class EnableTable{

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

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

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

      // Verifying weather conditions the table is disabintroduced
      Boolean bool = admin.isTableEnabintroduced("emp");
      System.out generally there.println(bool);

      // Disabling the table uperform HBaseAdmin object
      if(!bool){
         admin.enableTable("emp");
         System.out generally there.println("Table Enabintroduced");
      }
   }
}

Compile and execute the above program as shown becomelow.

$javac EnableTable.java
$java EnableTable

The following ought to become the out generally thereplace:

false
Table Enabintroduced

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 out generally thereplace 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
⇒ 'private

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 generate modifys to an existing table. Uperform this particular particular command, you can modify the maximum numbecomer of cellulars 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 cellulars of a column family.

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

In the following example, the maximum numbecomer of cellulars is set to 5.

hbase(main):003:0> alter 'emp', NAME ⇒ 'private data', VERSIONS ⇒ 5
Updating all regions with the brand new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 line(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 generate a table read only.

hbase>alter 't1', READONLY(option)

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

hbase(main):006:0> alter 'emp', READONLY
Updating all regions with the brand new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 line(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 presently generally there is a table named employee in HBase. It contains the following data:

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

   ROW                   COLUMN+CELL

line1 column = private:city, timestamp = 1418193767, value = hyderabad

line1 column = private:name, timestamp = 1418193806767, value = raju

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

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

1 line(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 regions with the brand new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 line(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
line1 column = private:city, timestamp = 14181936767, value = hyderabad

line1 column = private:name, timestamp = 1418193806767, value = raju

1 line(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 class. Follow the steps given becomelow to add a column family to a table.

Step 1

Instantiate the HBaseAdmin class.

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

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

Step 2

The addColumn() method requires a table name and an object of HColumnDescriptor class. Therefore quickiate the HColumnDescriptor class. The constructor of HColumnDescriptor in turn requires a column family name thead use is to become added. Here we are adding a column family named “con2rkDetails” to the existing “employee” table.

// Instantiating columnDescriptor object

HColumnDescriptor columnDescriptor = brand new
HColumnDescriptor("con2rkDetails");

Step 3

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

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

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

imslot java.io.IOException;

imslot org.apache.hadoop.conf.Configuration;

imslot org.apache.hadoop.hbase.HBaseConfiguration;
imslot org.apache.hadoop.hbase.HColumnDescriptor;
imslot org.apache.hadoop.hbase.MasterNotRunningException;
imslot org.apache.hadoop.hbase.care locatednt.HBaseAdmin;

public class AddColoumn{

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

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

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

      // Instantiating columnDescriptor class
      HColumnDescriptor columnDescriptor = brand new HColumnDescriptor("con2rkDetails");
      
      // Adding column family
      admin.addColumn("employee", columnDescriptor);
      System.out generally there.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 classrout generally theree 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 everything goes well, it will produce the following out generally thereplace:

column added

Depermiting a Column Family Uperform Java API

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

Step1

Instantiate the HBaseAdmin class.

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

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

Step2

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

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

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

imslot java.io.IOException;

imslot org.apache.hadoop.conf.Configuration;

imslot org.apache.hadoop.hbase.HBaseConfiguration;
imslot org.apache.hadoop.hbase.MasterNotRunningException;
imslot org.apache.hadoop.hbase.care locatednt.HBaseAdmin;

public class DepermiteColoumn{

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

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

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

      // Depermiting a column family
      admin.depermiteColumn("employee","con2rkDetails");
      System.out generally there.println("coloumn depermited"); 
   }
}

Compile and execute the above program as shown becomelow.

$javac DepermiteColumn.java
$java DepermiteColumn

The following ought to become the out generally thereplace:

column depermited

HBase – Exists

Existence of Table uperform HBase Shell

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

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

0 line(s) in 0.0750 2nds

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

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

0 line(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 class. Follow the steps given becomelow to verify the existence of a table in HBase.

Step 1

Instantiate the HBaseAdimn class

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

// Instantiating HBaseAdmin class
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 check the existence of a table in HBase uperform java API.

imslot java.io.IOException;

imslot org.apache.hadoop.hbase.HBaseConfiguration;
imslot org.apache.hadoop.conf.Configuration;
imslot org.apache.hadoop.hbase.care locatednt.HBaseAdmin;

public class TableExists{

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

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

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

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

Compile and execute the above program as shown becomelow.

$javac TableExists.java
$java TableExists 

The following ought to become the out generally thereplace:

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 line(s) in 1.4580 2nds

hbase(main):019:0> fall 'emp'
0 line(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 line(s) in 0.0730 2nds

fall_all

This command is used to fall the tables matching 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 presently generally there are tables named raja, rajani, rajendra, rajesh, and raju.

hbase(main):017:0> list
TABLE
raja
rajani
rajendra 
rajesh
raju
9 line(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 disabintroduced

Now you can depermite all of 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 class. Follow the steps given becomelow to depermite a table uperform java API.

Step 1

Instantiate the HBaseAdmin class.

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

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

Step 2

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

admin.disableTable("emp1");

Step 3

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

admin.depermiteTable("emp12");

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

imslot java.io.IOException;

imslot org.apache.hadoop.hbase.HBaseConfiguration;
imslot org.apache.hadoop.conf.Configuration;
imslot org.apache.hadoop.hbase.care locatednt.HBaseAdmin;

public class DepermiteTable {

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

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

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

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

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

Compile and execute the above program as shown becomelow.

$javac DepermiteTable.java
$java DepermiteTable

The following ought to become the out generally thereplace:

Table depermited

HBase – Shutting Down

exit

You exit the shell simply by typing the exit command.

hbase(main):021:0> exit

Stopping HBase

To stop HBase, blinese to the HBase home folder and kind the following command.

./bin/stop-hbase.sh

Stopping HBase Uperform Java API

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

Step 1

Instantiate the HbaseAdmin class.

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

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

Step 2

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

admin.shutdown();

Given becomelow is the program to stop the HBase.

imslot java.io.IOException;

imslot org.apache.hadoop.hbase.HBaseConfiguration;
imslot org.apache.hadoop.conf.Configuration;
imslot org.apache.hadoop.hbase.care locatednt.HBaseAdmin;

public class ShutDownHbase{

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

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

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

      // Shutting down HBase
      System.out generally there.println("Shutting down hbase");
      admin.shutdown();
   }
}

Compile and execute the above program as shown becomelow.

$javac ShutDownHbase.java
$java ShutDownHbase

The following ought to become the out generally thereplace:

Shutting down hbase

HBase – Care locatednt API

This chapter describecomes the java care locatednt API for HBase thead use is used to perform CRUD operations on HBase tables. HBase is composed in Java and has a Java Native API. Therefore it provides programmatic access to Data Manipulation Language (DML).

Class HBase Configuration

Adds HBase configuration files to a Configuration. This class becomedurationys to the org.apache.hadoop.hbase package.

Methods and description

S.No. Methods and Description
1

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

This method generates a Configuration with HBase resources.

Class HTable

HTable is an HBase internal class thead use represents an HBase table. It is an implementation of table thead use is used to communicate with a performle HBase table. This class becomedurationys to the org.apache.hadoop.hbase.care locatednt class.

Constructors

S.No. Constructors and Description
1

HTable()

2

HTable(TableName tableName, ClusterConnection interinterconnection, ExecutorService pool)

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

Methods and description

S.No. Methods and Description
1

void shut()

Relreare locatedves all the resources of the HTable.

2

void depermite(Depermite depermite)

Depermites the specified cellulars/line.

3

boolean exists(Get get)

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

4

Result get(Get get)

Retrieves particular cellulars from a given line.

5

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

Returns the Configuration object used 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 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.

Class Put

This class is used to perform Put operations for a performle line. It becomedurationys to the org.apache.hadoop.hbase.care locatednt package.

Constructors

S.No. Constructors and Description
1

Put(simply byte[] line)

Uperform this particular particular constructor, you can generate a Put operation for the specified line.

2

Put(simply byte[] lineArray, int lineOffset, int lineLength)

Uperform this particular particular constructor, you can generate a copy of the moveed-in line key to keep local.

3

Put(simply byte[] lineArray, int lineOffset, int lineLength, durationy ts)

Uperform this particular particular constructor, you can generate a copy of the moveed-in line key to keep local.

4

Put(simply byte[] line, durationy ts)

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

Methods

S.No. Methods and Description
1

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

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

2

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

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

3

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

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

4

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

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

Class Get

This class is used to perform Get operations on a performle line. This class becomedurationys to the org.apache.hadoop.hbase.care locatednt package.

Constructor

S.No. Constructor and Description
1

Get(simply byte[] line)

Uperform this particular particular constructor, you can generate a Get operation for the specified line.

2 Get(Get get)

Methods

S.No. Methods and Description
1

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

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

2

Get addFamily(simply byte[] family)

Retrieves all columns from the specified family.

Class Depermite

This class is used to perform Depermite operations on a performle line. To depermite an entire line, quickiate a Depermite object with the line to depermite. This class becomedurationys to the org.apache.hadoop.hbase.care locatednt package.

Constructor

S.No. Constructor and Description
1

Depermite(simply byte[] line)

Creates a Depermite operation for the specified line.

2

Depermite(simply byte[] lineArray, int lineOffset, int lineLength)

Creates a Depermite operation for the specified line and timestamp.

3

Depermite(simply byte[] lineArray, int lineOffset, int lineLength, durationy ts)

Creates a Depermite operation for the specified line and timestamp.

4

Depermite(simply byte[] line, durationy timestamp)

Creates a Depermite operation for the specified line and timestamp.

Methods

S.No. Methods and Description
1

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

Depermites the lacheck version of the specified column.

2

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

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

3

Depermite addFamily(simply byte[] family)

Depermites all versions of all columns of the specified family.

4

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

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

Class Result

This class is used to get a performle line result of a Get or a Scan query.

Constructors

S.No. Constructors
1

Result()

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

Methods

S.No. Methods and Description
1

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

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

2

simply byte[] getRow()

This method is used to retrieve the line key thead use corresponds to the line from which this particular particular Result was generated.

HBase – Create Data

Inserting Data uperform HBase Shell

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

  • place command,

  • add() method of Put class, and

  • place() method of HTable class.

As an example, we are going to generate the following table in HBase.

HBase Table

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

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

Inserting the First Row

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

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

Insert the remaining lines uperform the place command in the extake action same way. If you insert the whole table, you will get the following out generally thereplace.

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

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

1 column=private 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=private data:city, timestamp=1417524574905, value=chennai

2 column=private 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=private data:city, timestamp=1417524681780, value=delhi

3 column=private 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 class. You can save it uperform the place() method of the HTable class. These classes becomedurationy to the org.apache.hadoop.hbase.care locatednt package. Below given are the steps to generate data in a Table of HBase.

Step 1:Instantiate the Configuration Class

The Configuration class adds HBase configuration files to it’s object. You can generate a configuration object uperform the generate() method of the HbaseConfiguration class as shown becomelow.

Configuration conf = HbaseConfiguration.generate();

Step 2:Instantiate the HTable Class

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

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

Step 3: Instantiate the PutClass

To insert data into an HBase table, the add() method and it’s variants are used. This method becomedurationys to Put, presently generally therefore quickiate the place class. This class requires the line name you like to insert the data into, in string format. You can quickiate the Put class as shown becomelow.

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

Step 4: InsertData

The add() method of Put class is used to insert data. It requires 3 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 requireddish coloureddish coloureddish coloured lines, save the modifys simply by adding the place instance to the place() method of HTable class as shown becomelow.

hTable.place(p); 

Step 6: Close the HTable Instance

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

hTable.shut(); 

Given becomelow is the comppermite program to generate data in HBase Table.

imslot java.io.IOException;

imslot org.apache.hadoop.conf.Configuration;

imslot org.apache.hadoop.hbase.HBaseConfiguration;
imslot org.apache.hadoop.hbase.care locatednt.HTable;
imslot org.apache.hadoop.hbase.care locatednt.Put;
imslot org.apache.hadoop.hbase.util.Bytes;

public class InsertData{

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

      // Instantiating Configuration class
      Configuration config = HBaseConfiguration.generate();

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

      // Instantiating Put class
      // accepts a line name.
      Put p = brand new Put(Bytes.toBytes("line1")); 

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

      p.add(Bytes.toBytes("private"),
      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.out generally there.println("data inserted");
      
      // cloperform HTable
      hTable.shut();
   }
}

Compile and execute the above program as shown becomelow.

$javac InsertData.java
$java InsertData

The following ought to become the out generally thereplace:

data inserted

HBase – Update Data

Updating Data uperform HBase Shell

You can update an existing cellular 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’,’line ’,'Column family:column name',’brand new value’

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

Example

Suppose presently generally there is a table in HBase calintroduced emp with the following data.

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

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

hbase(main):002:0> place 'emp','line1','private:city','Delhi'
0 line(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
line1 column = private:name, timestamp = 1418035791555, value = raju
line1 column = private:city, timestamp = 1418274645907, value = Delhi
line1 column = professional:styleation, timestamp = 141857555,value = manager
line1 column = professional:salary, timestamp = 1418039555, value = 50000
1 line(s) in 0.0100 2nds

Updating Data Uperform Java API

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

Step 1: Instantiate the Configuration Class

Configuration class adds HBase configuration files to it’s object. You can generate a configuration object uperform the generate() method of the HbaseConfiguration class as shown becomelow.

Configuration conf = HbaseConfiguration.generate();

Step 2: Instantiate the HTable Class

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

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

Step 3: Instantiate the Put Class

To insert data into HBase Table, the add() method and it’s variants are used. This method becomedurationys to Put, presently generally therefore quickiate the place class. This class requires the line name you like to insert the data into, in string format. You can quickiate the Put class as shown becomelow.

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

Step 4: Update an Existing Cell

The add() method of Put class is used to insert data. It requires 3 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("private"),
Bytes.toBytes("city"),Bytes.toBytes("Delih"));

Step 5: Save the Data in Table

After inserting the requireddish coloureddish coloureddish coloured lines, save the modifys simply by adding the place instance
to the place() method of the HTable class as shown becomelow.

hTable.place(p); 

Step 6: Close HTable Instance

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

hTable.shut();

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

imslot java.io.IOException;

imslot org.apache.hadoop.conf.Configuration;

imslot org.apache.hadoop.hbase.HBaseConfiguration;
imslot org.apache.hadoop.hbase.care locatednt.HTable;
imslot org.apache.hadoop.hbase.care locatednt.Put;
imslot org.apache.hadoop.hbase.util.Bytes;

public class UpdateData{

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

      // Instantiating Configuration class
      Configuration config = HBaseConfiguration.generate();

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

      // Instantiating Put class
      //accepts a line name
      Put p = brand new Put(Bytes.toBytes("line1"));

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

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

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

Compile and execute the above program as shown becomelow.

$javac UpdateData.java
$java UpdateData

The following ought to become the out generally thereplace:

data Updated

HBase – Read Data

Reading Data uperform HBase Shell

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

get ’<table name>’,’line1’

Example

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

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

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

private : name timestamp = 1417521785385, value = ramu

professional: styleation timestamp = 1417521885277, value = manager

professional: salary timestamp = 1417521903862, value = 50000

4 line(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', ‘lineid’, {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', 'line1', {COLUMN ⇒ 'private:name'}
  COLUMN                CELL  
private:name timestamp = 1418035791555, value = raju
1 line(s) in 0.0080 2nds

Reading Data Uperform Java API

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

Step 1: Instantiate the Configuration Class

Configuration class adds HBase configuration files to it’s object. You can generate a configuration object uperform the generate() method of the HbaseConfiguration class as shown becomelow.

Configuration conf = HbaseConfiguration.generate();

Step 2: Instantiate the HTable Class

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

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

Step 3: Instantiate the Get Class

You can retrieve data from the HBase table uperform the get() method of the HTable class. This method extrworks a cellular from a given line. It requires a Get class object as parameter. Create it as shown becomelow.

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

Step 4: Read the Data

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

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

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

get.addFamily(private) 

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

get.addColumn(private, name) 

Step 5: Get the Result

Get the result simply by moveing your own Get class instance to the get method of the HTable class. This method returns the Result class 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 class provides the getValue() method to read the values from it’s instance. Use it as shown becomelow to read the values from the Result instance.

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

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

imslot java.io.IOException;

imslot org.apache.hadoop.conf.Configuration;

imslot org.apache.hadoop.hbase.HBaseConfiguration;
imslot org.apache.hadoop.hbase.care locatednt.Get;
imslot org.apache.hadoop.hbase.care locatednt.HTable;
imslot org.apache.hadoop.hbase.care locatednt.Result;
imslot org.apache.hadoop.hbase.util.Bytes;

public class RetriveData{

   public static void main(String[] args) thlines IOException, Exception{
   
      // Instantiating Configuration class
      Configuration config = HBaseConfiguration.generate();

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

      // Instantiating Get class
      Get g = brand new Get(Bytes.toBytes("line1"));

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

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

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

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

Compile and execute the above program as shown becomelow.

$javac RetriveData.java
$java RetriveData

The following ought to become the out generally thereplace:

name: Raju city: Delhi

HBase – Depermite Data

Depermiting a Specific Cell in a Table

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

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

Example

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

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

Depermiting All Cells in a Table

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

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

Example

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

hbase(main):007:0> depermiteall 'emp','1'
0 line(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 = private data:city, timestamp = 1417524574905, value = chennai 

2 column = private 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 = private data:city, timestamp = 1417524681780, value = delhi

3 column = private 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 class. Follow the steps given becomelow to depermite data from a table.

Step 1: Instantiate the Configuration Class

Configuration class adds HBase configuration files to it’s object. You can generate a configuration object uperform the generate() method of the the HbaseConfiguration class as shown becomelow.

Configuration conf = HbaseConfiguration.generate();

Step 2: Instantiate the HTable Class

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

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

Step 3: Instantiate the Depermite Class

Instantiate the Depermite class simply by moveing the lineid of the line thead use is to become depermited, in simply byte array format. You can furthermore move timestamp and Rowlock to this particular particular constructor.

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

Step 4: Select the Data to become Depermited

You can depermite the data uperform the depermite methods of the Depermite class. This class has various depermite methods. Choose the columns or column famiare locateds to become depermited uperform those methods. Take a look at the following examples thead use show the usage of Depermite class methods.

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

Step 5: Depermite the Data

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

table.depermite(depermite); 

Step 6: Close the HTableInstance

After depermiting the data, shut the HTable Instance.

table.shut();

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

imslot java.io.IOException;

imslot org.apache.hadoop.conf.Configuration;

imslot org.apache.hadoop.hbase.HBaseConfiguration;
imslot org.apache.hadoop.hbase.care locatednt.Depermite;
imslot org.apache.hadoop.hbase.care locatednt.HTable;
imslot org.apache.hadoop.hbase.util.Bytes;

public class DepermiteData {

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

      // Instantiating Configuration class
      Configuration conf = HBaseConfiguration.generate();

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

      // Instantiating Depermite class
      Depermite depermite = brand new Depermite(Bytes.toBytes("line1"));
      depermite.depermiteColumn(Bytes.toBytes("private"), Bytes.toBytes("name"));
      depermite.depermiteFamily(Bytes.toBytes("professional"));

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

      // cloperform the HTable object
      table.shut();
      System.out generally there.println("data depermited.....");
   }
}

Compile and execute the above program as shown becomelow.

$javac Depermitedata.java
$java DepermiteData

The following ought to become the out generally thereplace:

data depermited

HBase – Scan

Scaning uperform HBase Shell

The scan command is used to see 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 following 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 = private data:city, timestamp = 1417521848375, value = hyderabad
 
1 column = private 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 line(s) in 0.0370 2nds

Scanning Uperform Java API

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

imslot java.io.IOException;

imslot org.apache.hadoop.conf.Configuration;

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

imslot org.apache.hadoop.hbase.care locatednt.HTable;
imslot org.apache.hadoop.hbase.care locatednt.Result;
imslot org.apache.hadoop.hbase.care locatednt.ResultScanner;
imslot org.apache.hadoop.hbase.care locatednt.Scan;


public class ScanTable{

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

      // Instantiating Configuration class
      Configuration config = HBaseConfiguration.generate();

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

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

      // Scanning the requireddish coloureddish coloureddish coloured columns
      scan.addColumn(Bytes.toBytes("private"), Bytes.toBytes("name"));
      scan.addColumn(Bytes.toBytes("private"), 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.out generally there.println("Found line : " + result);
      //cloperform the scanner
      scanner.shut();
   }
}

Compile and execute the above program as shown becomelow.

$javac ScanTable.java
$java ScanTable 

The following ought to become the out generally thereplace:

Found line :
keyvalues={line1/private:city/1418275612888/Put/vlen=5/mvcc=0,
line1/private:name/1418035791555/Put/vlen=4/mvcc=0}

HBase – Count & Truncate

count

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

count ‘<table name>’ 

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

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

truncate

This command disables falls and reddish colouregenerates a table. The syntax of truncate is as follows:

hbase> truncate 'table name'

Example

Given becomelow is the example of truncate command. Here we have truncated the emp table.

hbase(main):011:0> truncate 'emp'
Truncating 'one' table (it may take a while):
   - Disabling table...
   - Truncating table...
   0 line(s) in 1.5950 2nds

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

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

HBase – Security

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

grant

The grant command grants specific propers such as read, write, execute, and admin on a table to a particular 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 generate privilege.
  • A – represents admin privilege.

Given becomelow is an example thead use 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 propers of a table. It’s syntax is as follows:

hbase> revoke <user>

The following 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 following code lists all the user permissions of ‘emp’ table.

hbase(main):013:0> user_permission 'emp'
SHARE
Previous articleSoftball
Next articleR

NO COMMENTS

LEAVE A REPLY