Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
How to use HBase Shell
3.
Starting HBase Shell
4.
HBase Shell Commands
5.
FAQs
6.
Key Takeaways
Last Updated: Mar 27, 2024

HBase Shell

Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

For communicating with HBase, we use HBase Shell. And it uses the Hadoop File System to store the data, which has a controller server and region servers. The data will be held in the form of areas (tables). Hence, these regions will be split up and stored in region servers. In addition, the primary server manages these region servers, and all these tasks take place on HDFS.

Also see, Multiple Granularity in DBMS

How to use HBase Shell

  • It is essential to quote all names in HBase Shell, for example, table and column words.
  • Also, commas delimit command parameters.
  • Type <Return> to run it just after entering a command
  • We use configuration dictionaries for creating and altering tables; they are Ruby Hashes. It looks like:
{'key1' => 'value1', 'key2' => 'value2', ...}

          Significantly, they will open and close with curly braces.

  • Commonly, all the keys are defined initially with constants like name, version compression, etc.
  • We have to see a (messy) list of all constants in the environment, type 'Object. Constants' then there are no requirements to quote constants.  
  • It is essential to use double-quoted hexadecimal representation to enter binary keys or values or use them.

For example

1 hbase> get 't1', "key\x03\x3f\xcd"
2 hbase> get 't1', "key\003\023\011"
3 hbase> put 't1', "test\xef\xff", 'f1:', "\x01\x33\x40"
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Starting HBase Shell

Using these commands, we can connect to our running HBase via the shell:

$ ./bin/hbase shell
HBase Shell; enter 'help<RETURN>' for the list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version: 0.90.0, r1001068, Fri MAY 24 13:55:42 PDT 2018
hbase(main):001:0>

HBase Shell Commands

  • General Commands
Status It provides the status of HBase, like the number of servers.
Version It represents the version of HBase being used.
Whoami It shows the information about the user.
table_help This command provides help for table-reference commands.
  • Data Definition Language
    Data Definition Language is the commands which operate on the tables. 
Create This command creates a table.
List It lists all the tables in HBase.
Disable This command disables a table.
Is_disabled It verifies if a table is disabled or not.
enable This command enables a table.
Is_enabled verifies whether a table is enabled or not.
Describe It shows the description of a table.
Alter This command alters a table.
Exists It verifies whether a table exists or not.
Drop This command drops a table from HBase.
Drop_all We drop the tables matching the 'regex' given in the command by this command.
Put This command places a cell item at a specified column in a specified row In a particular table.
Get It is used to fetch the contents of the row or a cell.
Delete we use the Delete command to delete a cell value in a table
Deleteall It is used to delete all the cells in a given row.
scan This command scans and returns the table data
Count We use the Count command to count and return the number of rows in a table.
Truncate Truncate command, disables, drops, and recreates a specified table.

Additional HBase Shell commands

  • pme_config: Provide the record table name to get deployment status, for example,
pme_config 'person'

The command also allows you to query the deployment progress. In particular, pme_config tracks the deployment status at two different phases:

  1. You can run pme_config with a record table name to track the quality of the table after you have deployed it.
  2. You can run pme_config with a path to the configuration archive to see the runtime deployment status for the configuration.

Pme_dump

  • 1. This command allows you to see the human-readable version of the binary data stored in the row. When typing the command, put the table name in single quotes.
  • 2. The command can help with debugging and troubleshooting, specifically for evaluating the metadata in the primary table and the contents of the Big Match index tables:
yourtable - The primary data table.
yourtable.pmememidx - The index table for members.
yourtable.pmeentidx - The index table for entities.
  • Pme_set_autocompare: Temporarily sets the autocomparerecords configuration property for the specified PME table.
  • Pme_set_autoderive: Temporarily sets the autoderiverecords configuration property for the specified PME table.
  • Pme_set_autolink: Temporarily sets the autolinkrecords configuration property for the identified PME table.
  • Pme_disable_all: Disables all tables in HBase that are pme_enabled.

FAQs

  1. In which scenario should HBase not be used?
    HBase is not suitable for classic transactional applications or even relational analytics. It is also not a complete substitute for HDFS when doing large batch MapReduce. If you need key-based access to data when storing or retrieving, then you should consider HBase.
     
  2. Can HBase run without Hadoop?
    HBase can be used without Hadoop. Running HBase in standalone mode will use the local file system. Arbitrary databases cannot be run on Hadoop because HDFS is an append-only file system and not POSIX compliant. Most SQL databases require the ability to seek and modify existing files.
     
  3. How HBase data is stored?
    Data is stored as byte arrays in the cells of the HBase table since There are no data types in HBase; The content or the value in the cell is versioned by the timestamp when the value is stored in the cell. So each cell of an HBase table may contain multiple versions of data.

Key Takeaways

We learned about HBase Shell and how it starts, and we also learned the HBase shell commands, i.e.general, data definition, and data manipulation. We got the idea of additional HBase shell commands.

Visit here to learn more about different topics related to database and management systems. Ninjas don't stop here. Check out the Top 100 SQL Problems to master frequently asked questions in big companies and land your dream job. Also, try  Coding Ninjas Studio to practice a wide range of DSA questions asked in many interviews.

Previous article
Hbase-Installation on Windows
Next article
HBase Commands
Live masterclass