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
Instantiate the HBaseAdimn class
// Instantiating configuration object
Configuration conf = HBaseConfiguration.create();
// Instantiating HBaseAdmin class
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{
// 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
以下应该是输出: