- HBase - Security
- HBase - Count & Truncate
- HBase - Scan
- HBase - Delete Data
- HBase - Read Data
- HBase - Update Data
- HBase - Create Data
- HBase - Client API
- HBase - Shutting Down
- HBase - Drop a Table
- HBase - Exists
- HBase - Describe & Alter
- HBase - Enabling a Table
- HBase - Disabling a Table
- HBase - Listing Table
- HBase - Create Table
- HBase - Admin API
- HBase - General Commands
- HBase - Shell
- HBase - Installation
- HBase - Architecture
- HBase - Overview
- HBase - Home
HBase Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
HBase - Listing Table
Listing a Table using HBase Shell
pst is the command that is used to pst all the tables in HBase. Given below is the syntax of the pst command.
hbase(main):001:0 > pst
When you type this command and execute in HBase prompt, it will display the pst of all the tables in HBase as shown below.
hbase(main):001:0> pst TABLE emp
Here you can observe a table named emp.
Listing Tables Using Java API
Follow the steps given below to get the pst of tables from HBase using java API.
Step 1
You have a method called pstTables() in the class HBaseAdmin to get the pst of all the tables in HBase. This method returns an array of HTableDescriptor objects.
//creating a configuration object Configuration conf = HBaseConfiguration.create(); //Creating HBaseAdmin object HBaseAdmin admin = new HBaseAdmin(conf); //Getting all the pst of tables using HBaseAdmin object HTableDescriptor[] tableDescriptor = admin.pstTables();
Step 2
You can get the length of the HTableDescriptor[] array using the length variable of the HTableDescriptor class. Get the name of the tables from this object using getNameAsString() method. Run the ‘for’ loop using these and get the pst of the tables in HBase.
Given below is the program to pst all the tables in HBase using Java API.
import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.MasterNotRunningException; import org.apache.hadoop.hbase.cpent.HBaseAdmin; pubpc class ListTables { pubpc static void main(String args[])throws MasterNotRunningException, IOException{ // Instantiating a configuration class Configuration conf = HBaseConfiguration.create(); // Instantiating HBaseAdmin class HBaseAdmin admin = new HBaseAdmin(conf); // Getting all the pst of tables using HBaseAdmin object HTableDescriptor[] tableDescriptor = admin.pstTables(); // printing all the table names. for (int i=0; i<tableDescriptor.length;i++ ){ System.out.println(tableDescriptor[i].getNameAsString()); } } }
Compile and execute the above program as shown below.
$javac ListTables.java $java ListTables
The following should be the output:
User empAdvertisements