Changeset 9 for sample/HBaseRecord.java


Ignore:
Timestamp:
Jun 13, 2008, 5:45:02 PM (16 years ago)
Author:
waue
Message:

comment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sample/HBaseRecord.java

    r8 r9  
    1 /*
    2  *  NCHC Hbase with map reduce sample code
    3  *  DemoHBaseSlink.java
     1/**
     2 * Program: HBaseRecord.java
     3 * Editor: Waue Chen
     4 * From :  NCHC. Taiwn
     5 * Last Update Date: 06/01/2008
    46 */
    57
    6 package tw.org.nchc.code;
    7 
    8 import java.io.IOException;
    9 import java.util.Iterator;
    10 
    11 import org.apache.hadoop.fs.Path;
    12 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
    13 import org.apache.hadoop.hbase.mapred.TableReduce;
    14 import org.apache.hadoop.io.LongWritable;
    15 import org.apache.hadoop.io.MapWritable;
    16 import org.apache.hadoop.io.Text;
    17 import org.apache.hadoop.mapred.JobClient;
    18 import org.apache.hadoop.mapred.JobConf;
    19 import org.apache.hadoop.mapred.OutputCollector;
    20 import org.apache.hadoop.mapred.Reporter;
    21 import org.apache.hadoop.mapred.lib.IdentityMapper;
    22 import org.apache.hadoop.mapred.lib.IdentityReducer;
    23 
    248/**
    25  * This sample code will put the indicate data to Hbase.
    26  * 1. put test.txt in t1 directory which content is
    27 ---------------
    28 name:locate:years
    29 waue:taiwan:1981
    30 shellon:taiwan:1981
    31 ---------------
    32  * 2. hadoop_root/$ bin/hadoop dfs -put t1 t1
    33  * 3. hbase_root/$ bin/hbase shell
    34  * 4. hql > create table t1_table("person");
    35  * 5. Come to Eclipse and run this code, and we will let database as that
    36  t1_table -> person
    37   ----------------
    38   |  name | locate | years |
    39   ----------------
    40   | waue  | taiwan | 1981 |
    41   ----------------
    42   | shellon | taiwan | 1981 |
    43   * 6. Go to hbase console, type : hql > select * from t1_table;
    44      
     9 * Purpose :
     10 *  Parse your record and then store in HBase.
     11 *
     12 * HowToUse :
     13 *  Make sure Hadoop file system and Hbase are running correctly.
     14 *  1. put test.txt in t1 directory which content is
     15  ---------------
     16  name:locate:years
     17  waue:taiwan:1981
     18  shellon:taiwan:1981
     19  ---------------
     20 *  2. hadoop_root/$ bin/hadoop dfs -put t1 t1
     21 *  3. hbase_root/$ bin/hbase shell
     22 *  4. hql > create table t1_table("person");
     23 *  5. Come to Eclipse and run this code, and we will let database as that
     24  t1_table -> person
     25    ----------------
     26    |  name | locate | years |
     27    | waue  | taiwan | 1981 |
     28    | shellon | taiwan | 1981 |
     29    ----------------
     30 * Check Result:
     31 *  Go to hbase console, type :
     32 *    hql > select * from t1_table;
    453308/06/06 12:20:48 INFO hbase.HTable: Creating scanner over t1_table starting at key
    4634+-------------------------+-------------------------+-------------------------+
     
    6654+-------------------------+-------------------------+-------------------------+
    67553 row(s) in set. (0.04 sec)
    68  **/
     56 */
     57
     58
     59
     60
     61package tw.org.nchc.code;
     62
     63import java.io.IOException;
     64import java.util.Iterator;
     65
     66import org.apache.hadoop.fs.Path;
     67import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
     68import org.apache.hadoop.hbase.mapred.TableReduce;
     69import org.apache.hadoop.io.LongWritable;
     70import org.apache.hadoop.io.MapWritable;
     71import org.apache.hadoop.io.Text;
     72import org.apache.hadoop.mapred.JobClient;
     73import org.apache.hadoop.mapred.JobConf;
     74import org.apache.hadoop.mapred.OutputCollector;
     75import org.apache.hadoop.mapred.Reporter;
     76import org.apache.hadoop.mapred.lib.IdentityMapper;
     77import org.apache.hadoop.mapred.lib.IdentityReducer;
     78
     79
    6980public class HBaseRecord {
    7081
    7182  /* Denify parameter */
    7283  // one column family: person; three column qualifier: name,locate,years
    73   static private String  baseId1 = "person:name";
     84  static private String  baseId1 ="person:name";
    7485  static private String  baseId2 ="person:locate";
    7586  static private String  baseId3 ="person:years";
     
    131142  public static void main(String[] args) throws IOException {
    132143    // which path of input files in Hadoop file system 
    133 
    134144   
    135145    HBaseRecord setup = new HBaseRecord();
Note: See TracChangeset for help on using the changeset viewer.