Deep dive into HBase Scan, Count and Truncate command and how to achieve security in HBase

Last updated on Oct 16 2021
Anudhati Reddy

Table of Contents

Deep dive into HBase Scan, Count and Truncate command and how to achieve security in HBase

HBase – Scan

Scanning using HBase Shell

The scan command is employed to view the info in HTable. Using the scan command, you can get the table info. Its syntax is as follows:

scan ‘<table name>’

Example

The following example shows the wayread data from a table using the scan command. Here we are reading the emp table.

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

ROW                           COLUMN + CELL

1 column = personal data:city, timestamp = 1417521848375, value = hyderabad

1 column = personal data:name, timestamp = 1417521785385, value = ramu

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

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

1 row(s) in 0.0370 seconds

Scanning Using Java API

The complete program to scan the entire table info using java API is as follows.

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;

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

import org.apache.hadoop.hbase.client.HTable;

import org.apache.hadoop.hbase.client.Result;

import org.apache.hadoop.hbase.client.ResultScanner;

import org.apache.hadoop.hbase.client.Scan;

public class ScanTable{

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

// Instantiating Configuration class

Configuration config = HBaseConfiguration.create();

// Instantiating HTable class

HTable table = new HTable(config, “emp”);

// Instantiating the Scan class

Scan scan = new Scan();

// Scanning the required columns

scan.addColumn(Bytes.toBytes(“personal”), Bytes.toBytes(“name”));

scan.addColumn(Bytes.toBytes(“personal”), 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.println(“Found row : ” + result);

//closing the scanner

scanner.close();

}

}

Compile and execute the above program as shown below.

$javac ScanTable.java

$java ScanTable

The following should be the output:

Found row :

keyvalues={row1/personal:city/1418275612888/Put/vlen=5/mvcc=0,

row1/personal:name/1418035791555/Put/vlen=4/mvcc=0}

HBase – Count & Truncate

count

You can count the number of rows of a table using the count command. Its syntax is as follows:

count ‘<table name>’

After deleting the first row, emp table will have two rows. Verify it as shown below.

hbase(main):023:0> count ’emp’

2 row(s) in 0.090 seconds

⇒ 2

truncate

This command disables drops and recreates a table. The syntax of truncate is as follows:

hbase> truncate ‘table name’

Example

Given below is that 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 row(s) in 1.5950 seconds

After truncating the table, use the scan command to verify. You’ll get a table with zero rows.

hbase(main):017:0> scan ‘emp’

ROW                  COLUMN + CELL

0 row(s) in 0.3110 seconds

HBase – Security

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

grant

The grant command grants specific rights like 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 create privilege.
  • A – represents admin privilege.

Given below is an example that grants all privileges to a user named ‘Tecklearn’.

hbase(main):018:0> grant ‘Tecklearn’, ‘RWXCA’

revoke

The revoke command is employed to revoke a user’s access rights of a table. Its syntax is as follows:

hbase> revoke <user>

The following code revokes all the permissions from the user named ‘Tecklearn’.

hbase(main):006:0> revoke ‘Tecklearn’

user_permission

This command is employed 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’

 

So, this brings us to the end of blog. This Tecklearn ‘Deep dive into HBase Scan, Count and Truncate command and how to achieve security in HBase’ helps you with commonly asked questions if you are looking out for a job in HBase and No-SQL Database Domain.

If you wish to learn HBase and build a career in HBase or No-SQL Database domain, then check out our interactive, Apache HBase Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/apache-hbase-training/

Apache HBase Training

About the Course

Tecklearn Apache HBase training will master the powerful NoSQL distributed database. You will learn HBase architecture, data analytics using HBase, integration with Hive, monitoring cluster using ZooKeeper and working on real-life industry projects. Build your career as a certified HBase professional through our hands-on training with real-world examples. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Apache HBase.

Why Should you take Apache HBase Training?

  • HBase is now the largest data-driven service serving top websites including Facebook Messaging Platform.
  • There is Strong demand for HBase qualified professionals and they are paid big bucks for the right skills.
  • According to indeed.com, the average pay of an HBase developer stands at $81,422 per annum.

What you will Learn in this Course?

Introduction to HBase and NoSQL

  • Introduction to HBase
  • Fundamentals of HBase
  • What is NoSQL
  • NoSQL Vs RDBMS
  • Why HBase
  • Where to use HBase

HBase Data Modelling

  • Data Modelling
  • HDFS vs. HBase
  • HBase Use Cases

HBase Architecture and Components

  • HBase Architecture
  • Components of HBase Cluster

HBase Installation

  • Prerequisites for HBase Installation
  • Installation Steps

Programming in HBase

  • Create an Eclipse Project for HBase
  • Simple Table Creation from Java in HBase
  • HBase API
  • HBase Shell
  • Primary operations and advanced operations

Integration of Hive with HBase

  • Create a table and insert data into it
  • Integration of Hive with HBase
  • HBase Mapping

Deep Dive into HBase

  • Input Data into HBase
  • File Loading
  • HDFS File
  • HBase handling files in File System
  • WAL
  • Seek Vs Transfer
  • HBase ACID Properties

Got a question for us? Please mention it in the comments section and we will get back to you.

 

 

 

 

0 responses on "Deep dive into HBase Scan, Count and Truncate command and how to achieve security in HBase"

Leave a Message

Your email address will not be published. Required fields are marked *