close
Warning:
Can't synchronize with repository "(default)" (Unsupported version control system "svn": /usr/lib/python2.7/dist-packages/libsvn/_delta.so: failed to map segment from shared object: Cannot allocate memory). Look in the Trac log for more information.
- Timestamp:
-
Sep 28, 2010, 6:33:33 PM (15 years ago)
- Author:
-
waue
- Comment:
-
--
Legend:
- Unmodified
- Added
- Removed
- Modified
-
v4
|
v5
|
|
17 | 17 | {{{ |
18 | 18 | #!java |
| 19 | |
19 | 20 | package org.nchc.hbase; |
20 | 21 | |
… |
… |
|
29 | 30 | |
30 | 31 | public 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); |
35 | 36 | |
36 | | // HTableDescriptor 透過 add() 方法來加入Column family |
37 | | htd.addFamily(new HColumnDescriptor(family)); |
| 37 | // HTableDescriptor 透過 add() 方法來加入Column family |
| 38 | htd.addFamily(new HColumnDescriptor(family)); |
38 | 39 | |
39 | | // HBaseConfiguration 能接收 hbase-site.xml 的設定值 |
40 | | HBaseConfiguration config = new HBaseConfiguration(); |
| 40 | // HBaseConfiguration 能接收 hbase-site.xml 的設定值 |
| 41 | HBaseConfiguration config = new HBaseConfiguration(); |
41 | 42 | |
42 | | // 檔案的操作則使用 HBaseAdmin |
43 | | HBaseAdmin admin = new HBaseAdmin(config); |
| 43 | // 檔案的操作則使用 HBaseAdmin |
| 44 | HBaseAdmin admin = new HBaseAdmin(config); |
44 | 45 | |
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); |
50 | 51 | |
51 | | // 建立 |
52 | | admin.createTable(htd); |
53 | | } |
54 | | } |
| 52 | // 建立 |
| 53 | admin.createTable(htd); |
| 54 | } |
| 55 | } |
55 | 56 | |
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; |
67 | 61 | |
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]; |
69 | 71 | |
70 | | createHBaseTable(tablename, family); |
71 | | } |
| 72 | System.out.println("1. create table :" + tablename); |
| 73 | |
| 74 | createHBaseTable(tablename, family); |
| 75 | } |
72 | 76 | } |
73 | 77 | |