使用HBase Shell存在表
您可以使用 exists 命令验证表是否存在.以下示例显示如何使用此命令.
hbase(main):024:0> exists 'emp'Table emp does exist0 row(s) in 0.0750 seconds==================================================================hbase(main):015:0> exists 'student'Table student does not exist0 row(s) in 0.0480 seconds
验证存在使用Java API的表
您可以使用 HBaseAdmin 类的 tableExists()方法验证HBase中是否存在表.按照下面给出的步骤验证HBase中是否存在表.
步骤1
Instantiate the HBaseAdimn class// Instantiating configuration objectConfiguration conf = HBaseConfiguration.create();// Instantiating HBaseAdmin classHBaseAdmin admin = new HBaseAdmin(conf);
第2步
使用 tableExists()方法验证表的存在.
以下是使用java API测试HBase中是否存在表的java程序.
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); }}
编译并执行上述程序,如下所示.
$ javac TableExists.java $ java TableExists
以下内容应为输出:
true