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
廣告