HBase - 存在



使用 HBase 外壳的表存在

使用 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 程序,用于使用 Java API 测试 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);
   }
} 

编译并执行上述程序,如下所示。

$javac TableExists.java
$java TableExists 

输出应如下所示

true
广告
© . All rights reserved.