Existence of Table using HBase Shell
You can verify the existence of a table using the exists command. The following example shows how to use this command.
hbase(main):024:0> exists 'emp' Table emp does exist 0 row(s) in 0.0750 seconds ================================================================== hbase(main):015:0> exists 'student' Table student does not exist 0 row(s) in 0.0480 seconds
Verifying the Existence of Table Using Java API
You can verify the existence of a table in HBase using the tableExists() method of the HBaseAdmin class. Follow the steps given below to verify the existence of a table in HBase.
Step 1
Instantiate the HBaseAdimn class // Instantiating configuration object Configuration conf = HBaseConfiguration.create(); // Instantiating HBaseAdmin class HBaseAdmin admin = new HBaseAdmin(conf);
Step 2
Verify the existence of the table using the tableExists( ) method.
Given below is the java program to test the existence of a table in HBase using java API.
import java.io.IOException; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.client.HBaseAdmin; public class TableExists{ public static void main(String args[])throws IOException{ // Instantiating configuration class Configuration conf = HBaseConfiguration.create(); // Instantiating HBaseAdmin class HBaseAdmin admin = new HBaseAdmin(conf); // Verifying the existance of the table boolean bool = admin.tableExists("emp"); System.out.println( bool); } }
Compile and execute the above program as shown below.
$javac TableExists.java $java TableExists
The following should be the output:
true