Changes between Version 2 and Version 3 of waue/2010/0204-01


Ignore:
Timestamp:
Feb 3, 2010, 9:50:33 PM (14 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2010/0204-01

    v2 v3  
    44{{{
    55#!java
     6package tsmc;
     7
     8import java.io.IOException;
     9
     10import org.apache.hadoop.hbase.HBaseConfiguration;
     11import org.apache.hadoop.hbase.HColumnDescriptor;
     12import org.apache.hadoop.hbase.HTableDescriptor;
     13import org.apache.hadoop.hbase.client.HBaseAdmin;
     14
     15public class CreateTable {
     16        public static void createHBaseTable(String tablename, String family)
     17                        throws IOException {
     18                // HTableDescriptor contains the name of an HTable, and its column
     19                // families
     20                // HTableDescriptor 用來描述table的屬性
     21                HTableDescriptor htd = new HTableDescriptor(tablename);
     22                // HColumnDescriptor HColumnDescriptor contains information about a
     23                // column family such as the number of versions, compression settings,
     24                // etc.
     25                // HTableDescriptor 透過 add() 方法來加入Column family
     26
     27                htd.addFamily(new HColumnDescriptor(family));
     28
     29                // HBaseConfiguration 能接收 hbase-site.xml 的設定值
     30                HBaseConfiguration config = new HBaseConfiguration();
     31                // 檔案的操作則使用 HBaseAdmin
     32                HBaseAdmin admin = new HBaseAdmin(config);
     33                // 檢查
     34                if (admin.tableExists(tablename)) {
     35                        System.out.println("Table: " + tablename + "Existed.");
     36                } else {
     37                        System.out.println("create new table: " + tablename);
     38                        // 建立
     39                        admin.createTable(htd);
     40                }
     41        }
     42
     43        static public void main(String argv[]) throws IOException {
     44
     45                String tablename = "tsmc";
     46                String family = "Detail";
     47
     48                System.out.println("1. create table :" + tablename);
     49
     50                createHBaseTable(tablename, family);
     51        }
     52}
    653
    754}}}