Changeset 18 for sample/WordCountIntoHBase.java
- Timestamp:
- Jul 2, 2008, 3:10:09 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sample/WordCountIntoHBase.java
r8 r18 3 3 * Editor: Waue Chen 4 4 * From : NCHC. Taiwn 5 * Last Update Date: 06/10/2008 5 * Last Update Date: 07/02/2008 6 * Upgrade to 0.17 6 7 */ 7 8 … … 43 44 44 45 /* setup parameters */ 45 // $Input_Path. Please make sure the path is correct and contains input files 46 // $Input_Path. Please make sure the path is correct and contains input 47 // files 46 48 static final String Input_Path = "/user/waue/simple"; 49 47 50 // Hbase table name, the program will create it 48 51 static final String Table_Name = "word_count5"; 52 49 53 // column name, the program will create it 50 static final String colstr = "word:text" 51 54 static final String colstr = "word:text"; 55 52 56 // constructor 53 57 private WordCountIntoHBase() { … … 57 61 // set (column_family:column_qualify) 58 62 private static final Text col = new Text(WordCountIntoHBase.colstr); 63 59 64 // this map holds the columns per row 60 65 private MapWritable map = new MapWritable(); 66 61 67 public void reduce(LongWritable key, Iterator<Text> values, 62 68 OutputCollector<Text, MapWritable> output, Reporter reporter) 63 69 throws IOException { 64 70 // contents must be ImmutableBytesWritable 65 ImmutableBytesWritable bytes = 66 new ImmutableBytesWritable(values.next().getBytes());71 ImmutableBytesWritable bytes = new ImmutableBytesWritable(values 72 .next().getBytes()); 67 73 map.clear(); 68 // write data 74 // write data 69 75 map.put(col, bytes); 70 76 // add the row with the key as the row id … … 76 82 * Runs the demo. 77 83 */ 78 public static void main(String[] args) throws IOException { 84 public static void main(String[] args) throws IOException { 79 85 // parse colstr to split column family and column qualify 80 86 String tmp[] = colstr.split(":"); 81 String Column_Family = tmp[0] +":";82 String CF[] = { Column_Family};83 // check whether create table or not , we don't admit \ 87 String Column_Family = tmp[0] + ":"; 88 String CF[] = { Column_Family }; 89 // check whether create table or not , we don't admit \ 84 90 // the same name but different structure 85 BuildHTable build_table = new BuildHTable(Table_Name, CF);91 BuildHTable build_table = new BuildHTable(Table_Name, CF); 86 92 if (!build_table.checkTableExist(Table_Name)) { 87 93 if (!build_table.createTable()) { 88 94 System.out.println("create table error !"); 89 95 } 90 }else{ 91 System.out.println("Table \"" + Table_Name +"\" has already existed !"); 96 } else { 97 System.out.println("Table \"" + Table_Name 98 + "\" has already existed !"); 92 99 } 93 100 int mapTasks = 1; … … 100 107 conf.setNumMapTasks(mapTasks); 101 108 conf.setNumReduceTasks(reduceTasks); 102 conf.setInputPath(new Path(Input_Path)); 109 // 0.16 110 // conf.setInputPath(new Path(Input_Path)); 111 Convert.setInputPath(conf, new Path(Input_Path)); 103 112 conf.setMapperClass(IdentityMapper.class); 104 113 conf.setCombinerClass(IdentityReducer.class);
Note: See TracChangeset
for help on using the changeset viewer.