- HBase 教程
- HBase - 首頁
- HBase - 概述
- HBase - 架構
- HBase - 安裝
- HBase - Shell
- HBase - 通用命令
- HBase - Admin API
- HBase - 建立表
- HBase - 列出表
- HBase - 停用表
- HBase - 啟用表
- HBase - Describe 和 Alter
- HBase - Exists
- HBase - 刪除表
- HBase - 關閉
- HBase - 客戶端 API
- HBase - 建立資料
- HBase - 更新資料
- HBase - 讀取資料
- HBase - 刪除資料
- HBase - Scan
- HBase - Count 和 Truncate
- HBase - 安全性
- HBase 資源
- HBase - 問題與解答
- HBase - 快速指南
- HBase - 有用資源
HBase - 啟用表
使用 HBase Shell 啟用表
啟用表的語法
enable ‘emp’
示例
以下給出了啟用表的示例。
hbase(main):005:0> enable 'emp' 0 row(s) in 0.4580 seconds
驗證
啟用表後,請掃描該表。如果可以看到架構,則表示表已成功啟用。
hbase(main):006:0> scan 'emp' ROW COLUMN + CELL 1 column = personal data:city, timestamp = 1417516501, value = hyderabad 1 column = personal data:name, timestamp = 1417525058, value = ramu 1 column = professional data:designation, timestamp = 1417532601, value = manager 1 column = professional data:salary, timestamp = 1417524244109, value = 50000 2 column = personal data:city, timestamp = 1417524574905, value = chennai 2 column = personal data:name, timestamp = 1417524556125, value = ravi 2 column = professional data:designation, timestamp = 14175292204, value = sr:engg 2 column = professional data:salary, timestamp = 1417524604221, value = 30000 3 column = personal data:city, timestamp = 1417524681780, value = delhi 3 column = personal data:name, timestamp = 1417524672067, value = rajesh 3 column = professional data:designation, timestamp = 14175246987, value = jr:engg 3 column = professional data:salary, timestamp = 1417524702514, value = 25000 3 row(s) in 0.0400 seconds
is_enabled
此命令用於查詢表是否已啟用。其語法如下
hbase> is_enabled 'table name'
在以下程式碼中,我們驗證名為 emp 的表是否已啟用。如果已啟用,它將返回 true,如果沒有啟用,它將返回 false。
hbase(main):031:0> is_enabled 'emp' true 0 row(s) in 0.0440 seconds
使用 Java API 啟用表
若要驗證表是否已啟用,請使用 isTableEnabled() 方法,若要啟用表,請使用 enableTable() 方法。這些方法屬於 HBaseAdmin 類。按照以下步驟啟用表。
步驟 1
如下所示,例項化 HBaseAdmin 類。
// Creating configuration object Configuration conf = HBaseConfiguration.create(); // Creating HBaseAdmin object HBaseAdmin admin = new HBaseAdmin(conf);
步驟 2
使用 isTableEnabled() 方法驗證表是否已啟用,如下所示。
Boolean bool = admin.isTableEnabled("emp");
步驟 3
如果表未停用,請按照如下方式將其停用。
if(!bool){
admin.enableTable("emp");
System.out.println("Table enabled");
}
以下給出了完整程式,用於驗證表是否已啟用,如果沒有啟用,則說明如何啟用它。
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class EnableTable{
public static void main(String args[]) throws MasterNotRunningException, IOException{
// Instantiating configuration class
Configuration conf = HBaseConfiguration.create();
// Instantiating HBaseAdmin class
HBaseAdmin admin = new HBaseAdmin(conf);
// Verifying whether the table is disabled
Boolean bool = admin.isTableEnabled("emp");
System.out.println(bool);
// Enabling the table using HBaseAdmin object
if(!bool){
admin.enableTable("emp");
System.out.println("Table Enabled");
}
}
}
如下所示,編譯並執行上述程式。
$javac EnableTable.java $java EnableTable
輸出應如下所示
false Table Enabled
廣告