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
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.
Instantiate the HBaseAdimn class // Instantiating configuration object Configuration conf = HBaseConfiguration.create(); // Instantiating HBaseAdmin class HBaseAdmin admin = new HBaseAdmin(conf);
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