HBase - Exists
使用 HBase Shell 确认表是否存在
您可以使用 exists 命令验证表是否存在。以下示例显示了如何使用此命令。
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
使用 Java API 验证表的存在
您可以使用 HBaseAdmin 类的 tableExists() 方法验证 HBase 中表的存在。按照下面给出的步骤验证 HBase 中表的存在。
步骤 1
实例化 HBaseAdimn 类 // 实例化配置对象 Configuration conf = HBaseConfiguration.create(); // 实例化 HBaseAdmin 类 HBaseAdmin 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{
// 实例化配置类
Configuration conf = HBaseConfiguration.create();
// 实例化 HBaseAdmin 类
HBaseAdmin admin = new HBaseAdmin(conf);
// 验证表是否存在
boolean bool = admin.tableExists("emp");
System.out.println( bool);
}
}
编译并执行上述程序,如下所示。
$javac TableExists.java $java TableExists
输出应如下所示:
true

