Changes between Version 4 and Version 5 of NCHCCloudCourse100929_4_HBEX
- Timestamp:
- Sep 28, 2010, 6:33:33 PM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
NCHCCloudCourse100929_4_HBEX
v4 v5 17 17 {{{ 18 18 #!java 19 19 20 package org.nchc.hbase; 20 21 … … 29 30 30 31 public class CreateTable { 31 32 33 34 32 public static void createHBaseTable(String tablename, String family) 33 throws IOException { 34 // HTableDescriptor 用來描述table的屬性 35 HTableDescriptor htd = new HTableDescriptor(tablename); 35 36 36 37 37 // HTableDescriptor 透過 add() 方法來加入Column family 38 htd.addFamily(new HColumnDescriptor(family)); 38 39 39 40 40 // HBaseConfiguration 能接收 hbase-site.xml 的設定值 41 HBaseConfiguration config = new HBaseConfiguration(); 41 42 42 43 43 // 檔案的操作則使用 HBaseAdmin 44 HBaseAdmin admin = new HBaseAdmin(config); 44 45 45 46 47 48 49 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 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