Changes between Version 4 and Version 5 of NCHCCloudCourse100929_4_HBEX


Ignore:
Timestamp:
Sep 28, 2010, 6:33:33 PM (14 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NCHCCloudCourse100929_4_HBEX

    v4 v5  
    1717{{{
    1818#!java
     19
    1920package org.nchc.hbase;
    2021
     
    2930
    3031public class CreateTable {
    31         public static void createHBaseTable(String tablename, String family)
    32                         throws IOException {
    33                 // HTableDescriptor 用來描述table的屬性
    34                 HTableDescriptor htd = new HTableDescriptor(tablename);
     32  public static void createHBaseTable(String tablename, String family)
     33      throws IOException {
     34    // HTableDescriptor 用來描述table的屬性
     35    HTableDescriptor htd = new HTableDescriptor(tablename);
    3536
    36                 // HTableDescriptor 透過 add() 方法來加入Column family
    37                 htd.addFamily(new HColumnDescriptor(family));
     37    // HTableDescriptor 透過 add() 方法來加入Column family
     38    htd.addFamily(new HColumnDescriptor(family));
    3839
    39                 // HBaseConfiguration 能接收 hbase-site.xml 的設定值
    40                 HBaseConfiguration config = new HBaseConfiguration();
     40    // HBaseConfiguration 能接收 hbase-site.xml 的設定值
     41    HBaseConfiguration config = new HBaseConfiguration();
    4142
    42                 // 檔案的操作則使用 HBaseAdmin
    43                 HBaseAdmin admin = new HBaseAdmin(config);
     43    // 檔案的操作則使用 HBaseAdmin
     44    HBaseAdmin admin = new HBaseAdmin(config);
    4445
    45                 // 檢查
    46                 if (admin.tableExists(tablename)) {
    47                         System.out.println("Table: " + tablename + "Existed.");
    48                 } else {
    49                         System.out.println("create new table: " + tablename);
     46    // 檢查
     47    if (admin.tableExists(tablename)) {
     48      System.out.println("Table: " + tablename + "Existed.");
     49    } else {
     50      System.out.println("create new table: " + tablename);
    5051
    51                         // 建立
    52                         admin.createTable(htd);
    53                 }
    54         }
     52      // 建立
     53      admin.createTable(htd);
     54    }
     55  }
    5556
    56         static public void main(String argv[]) throws IOException {
    57                
    58                 String[] otherArgs = new GenericOptionsParser(new Configuration(), argv)
    59                                 .getRemainingArgs();
    60                 if (otherArgs.length < 2) {
    61                         System.out.println("CreateTable <newTableName> <Family>");
    62                         return;
    63                 }
    64                
    65                 String tablename = otherArgs[0];
    66                 String family = otherArgs[1];
     57  static public void main(String argv[]) throws IOException {
     58    // eclipse only
     59//        String[] args = {"tsmc","Detail"};
     60//        argv = args;
    6761
    68                 System.out.println("1. create table :" + tablename);
     62    String[] otherArgs = new GenericOptionsParser(new Configuration(), argv)
     63        .getRemainingArgs();
     64    if (otherArgs.length < 2) {
     65      System.out.println("CreateTable <newTableName> <Family>");
     66      return;
     67    }
     68   
     69    String tablename = otherArgs[0];
     70    String family = otherArgs[1];
    6971
    70                 createHBaseTable(tablename, family);
    71         }
     72    System.out.println("1. create table :" + tablename);
     73
     74    createHBaseTable(tablename, family);
     75  }
    7276}
    7377