
- HBase 教程
- HBase - 主頁
- HBase - 概述
- HBase - 架構
- HBase - 安裝
- HBase - Shell
- HBase - 通用命令
- HBase - 管理 API
- HBase - 建立表
- HBase - 列出表
- HBase - 停用表
- HBase - 啟用表
- HBase - Describe 和 Alter
- HBase - Exists
- HBase - 刪除表
- HBase - 關閉
- HBase - 客戶端 API
- HBase - 建立資料
- HBase - 更新資料
- HBase - 讀取資料
- HBase - 刪除資料
- HBase - 掃描
- HBase - Count 和 Truncate
- HBase - 安全性
- HBase 資源
- HBase - 問題和答案
- HBase - 快速指南
- HBase - 實用資源
HBase - 掃描
使用 HBase Shell 掃描
scan 命令用於檢視 HTable 中的資料。使用 scan 命令,你可以獲取表資料。其語法如下所示
scan ‘<table name>’
示例
以下示例說明了如何使用 scan 命令從表讀取資料。此處我們正在讀取 emp 表。
hbase(main):010:0> scan 'emp' ROW COLUMN + CELL 1 column = personal data:city, timestamp = 1417521848375, value = hyderabad 1 column = personal data:name, timestamp = 1417521785385, value = ramu 1 column = professional data:designation, timestamp = 1417585277,value = manager 1 column = professional data:salary, timestamp = 1417521903862, value = 50000 1 row(s) in 0.0370 seconds
使用 Java API 掃描
使用 java API 掃描整個表資料的完整程式如下所示。
import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; public class ScanTable{ public static void main(String args[]) throws IOException{ // Instantiating Configuration class Configuration config = HBaseConfiguration.create(); // Instantiating HTable class HTable table = new HTable(config, "emp"); // Instantiating the Scan class Scan scan = new Scan(); // Scanning the required columns scan.addColumn(Bytes.toBytes("personal"), Bytes.toBytes("name")); scan.addColumn(Bytes.toBytes("personal"), Bytes.toBytes("city")); // Getting the scan result ResultScanner scanner = table.getScanner(scan); // Reading values from scan result for (Result result = scanner.next(); result != null; result = scanner.next()) System.out.println("Found row : " + result); //closing the scanner scanner.close(); } }
根據需要編譯並執行上述程式,如下所示。
$javac ScanTable.java $java ScanTable
以下應為輸出
Found row : keyvalues={row1/personal:city/1418275612888/Put/vlen=5/mvcc=0, row1/personal:name/1418035791555/Put/vlen=4/mvcc=0}
廣告