Hbase-exists

提供:Dev Guides
移動先:案内検索

HBase-存在

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

出力は次のようになります。

true