可以使用exists命令驗(yàn)證表的存在。下面的示例演示了如何使用這個(gè)命令。
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
可以使用HBaseAdmin類的tableExists()方法驗(yàn)證表在HBase中是否存在。按照下面給出的步驟驗(yàn)證HBase表存在。
Instantiate the HBaseAdimn class // Instantiating configuration object Configuration conf = HBaseConfiguration.create(); // Instantiating HBaseAdmin class HBaseAdmin admin = new HBaseAdmin(conf);
使用tableExists()方法來驗(yàn)證表的存在。
下面給出的是使用java程序中的Java API來測(cè)試一個(gè)HBase表的存在。
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); } }
編譯和執(zhí)行上述程序如下所示。
$javac TableExists.java $java TableExists
下面列出的是輸出:
true