Changes between Version 1 and Version 2 of waue/2009/0626


Ignore:
Timestamp:
Jun 26, 2009, 3:21:44 PM (15 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2009/0626

    v1 v2  
     1= 新 hbase 解析 =
     2 * hbase 已經到0.19.3了,可惜的是 hbase 0.18.1的api及文件都已經從官方網頁被拿掉了,所幸hbase 0.18 與hbase 0.19相差無幾
     3 * hbase 0.1.3 到 hbase 0.19.3 中間好像已經包含了十幾代,但是其實類似java 1.4 直接跳躍 到 java 5 一樣,hbase 0.1.3 -> hbase 0.2.x -> hbase 0.18.x -> hbase 0.19.x
     4   * 從 hbase 0.18.x 之後,其版本名稱就直接對應hadoop 的版本名稱,如 hbase 0.18 搭配 hadoop 0.18 , hbase 0.19 搭配hadoop 0.19
     5 * 筆者開發hbase時是 hbase 0.13的時代,現在又重拾舊業,發現已經差很多了。如
     6 * 找資料:
     7   * hbase 0.13 : select * from 'table_name'
     8   * hbase 0.19 : scan 'table_name'
     9 * 資料庫結構:
     10   * hbase 0.13 :
     11|| || column_family:column_quolify1|| column_family:column_quolify2|| column_family:column_quolify3||
     12|| time stamp 2 || cell_value1 || cell_value2|| cell_value3||
     13|| time stamp 1 || cell_value1 || cell_value2|| cell_value3||
     14   * hbase 0.19 : 加入 row 這個結構
     15
     16
     17
     18{{{
     19#!java
     20
     21                HBaseConfiguration config = new HBaseConfiguration();
     22}}}
     23
     24{{{
     25#!java
     26                HBaseAdmin admin = new HBaseAdmin(config);
     27                if (!admin.tableExists(table_name)) {
     28                        System.out.println("HTable : " + table_name
     29                                        + "  creating ... please wait");
     30                        HTableDescriptor tableDesc = new HTableDescriptor(table_name);
     31                        // add column family
     32                        tableDesc.addFamily(new HColumnDescriptor(colomn_family));
     33                        admin.createTable(tableDesc);
     34                }
     35}}}
     36
     37{{{
     38#!java
     39
     40               
     41                BatchUpdate batchUpdate = new BatchUpdate(hbase_row);
     42                batchUpdate.put(colomn_family+column_quolify, Bytes.toBytes(value));
     43                batchUpdate.delete(colomn_family+"cellIWantDeleted");
     44}}}
     45
     46{{{
     47#!java
     48                HTable table = new HTable(config, table_name);
     49                table.commit(batchUpdate);
     50}}}
     51
     52{{{
     53#!java
     54
     55                Cell cell = table.get(hbase_row, colomn_family+column_quolify);
     56                System.out.print(cell.getValue());
     57
     58}}}
     59
     60{{{
     61#!java
     62                Scanner scanner =
     63                table.getScanner(new String[] { colomn_family+column_quolify });
     64
     65                RowResult rowResult = scanner.next();
     66
     67                while (rowResult != null) {
     68
     69                        System.out.println("Found row: "
     70                                        + Bytes.toString(rowResult.getRow())
     71                                        + " with value: "
     72                                        + rowResult.get(Bytes
     73                                                        .toBytes(colomn_family+column_quolify)));
     74                        rowResult = scanner.next();
     75                }
     76
     77                for (RowResult result : scanner) {
     78                        System.out.println("Found row: "
     79                                        + Bytes.toString(rowResult.getRow())
     80                                        + " with value: "
     81                                        + rowResult.get(Bytes
     82                                                        .toBytes(colomn_family+column_quolify)));
     83                }
     84
     85                scanner.close();
     86
     87
     88
     89}}}
     90
     91
     92 * 完整程式碼如下
     93
    194{{{
    295#!java