| | 1 | 說明: |
| | 2 | |
| | 3 | This sample code will put the indicate data to Hbase. |
| | 4 | |
| | 5 | 執行方式 : |
| | 6 | {{{ |
| | 7 | |
| | 8 | 1. put test.txt in t1 directory which content is |
| | 9 | |
| | 10 | --------------- |
| | 11 | |
| | 12 | name:locate:years |
| | 13 | |
| | 14 | waue:taiwan:1981 |
| | 15 | |
| | 16 | shellon:taiwan:1981 |
| | 17 | |
| | 18 | --------------- |
| | 19 | |
| | 20 | 2. hadoop_root/$ bin/hadoop dfs -put t1 t1 |
| | 21 | |
| | 22 | 3. hbase_root/$ bin/hbase shell |
| | 23 | |
| | 24 | 4. hql > create table t1_table("person"); |
| | 25 | |
| | 26 | 5. Come to Eclipse and run this code, and we will let database as that |
| | 27 | |
| | 28 | t1_table -> person |
| | 29 | |
| | 30 | ---------------- |
| | 31 | |
| | 32 | | name | locate | years | |
| | 33 | |
| | 34 | ---------------- |
| | 35 | |
| | 36 | | waue | taiwan | 1981 | |
| | 37 | |
| | 38 | ---------------- |
| | 39 | |
| | 40 | | shellon | taiwan | 1981 | |
| | 41 | |
| | 42 | * 6. Go to hbase console, type : hql > select * from t1_table; |
| | 43 | }}} |
| | 44 | |
| | 45 | 結果: |
| | 46 | }}} |
| | 47 | 08/06/06 12:20:48 INFO hbase.HTable: Creating scanner over t1_table starting at key |
| | 48 | |
| | 49 | +-------------------------+-------------------------+-------------------------+ |
| | 50 | |
| | 51 | | Row | Column | Cell | |
| | 52 | |
| | 53 | +-------------------------+-------------------------+-------------------------+ |
| | 54 | |
| | 55 | | 0 | person:locate | locate | |
| | 56 | |
| | 57 | +-------------------------+-------------------------+-------------------------+ |
| | 58 | |
| | 59 | | 0 | person:name | name | |
| | 60 | |
| | 61 | +-------------------------+-------------------------+-------------------------+ |
| | 62 | |
| | 63 | | 0 | person:years | years | |
| | 64 | |
| | 65 | +-------------------------+-------------------------+-------------------------+ |
| | 66 | |
| | 67 | | 19 | person:locate | taiwan | |
| | 68 | |
| | 69 | +-------------------------+-------------------------+-------------------------+ |
| | 70 | |
| | 71 | | 19 | person:name | waue | |
| | 72 | |
| | 73 | +-------------------------+-------------------------+-------------------------+ |
| | 74 | |
| | 75 | | 19 | person:years | 1981 | |
| | 76 | |
| | 77 | +-------------------------+-------------------------+-------------------------+ |
| | 78 | |
| | 79 | | 36 | person:locate | taiwan | |
| | 80 | |
| | 81 | +-------------------------+-------------------------+-------------------------+ |
| | 82 | |
| | 83 | | 36 | person:name | shellon | |
| | 84 | |
| | 85 | +-------------------------+-------------------------+-------------------------+ |
| | 86 | |
| | 87 | | 36 | person:years | 1981 | |
| | 88 | |
| | 89 | +-------------------------+-------------------------+-------------------------+ |
| | 90 | |
| | 91 | 3 row(s) in set. (0.04 sec) |
| | 92 | |
| | 93 | }}} |
| 47 | | |
| 48 | | |
| 49 | | /** |
| 50 | | |
| 51 | | * This sample code will put the indicate data to Hbase. |
| 52 | | |
| 53 | | * 1. put test.txt in t1 directory which content is |
| 54 | | |
| 55 | | --------------- |
| 56 | | |
| 57 | | name:locate:years |
| 58 | | |
| 59 | | waue:taiwan:1981 |
| 60 | | |
| 61 | | shellon:taiwan:1981 |
| 62 | | |
| 63 | | --------------- |
| 64 | | |
| 65 | | * 2. hadoop_root/$ bin/hadoop dfs -put t1 t1 |
| 66 | | |
| 67 | | * 3. hbase_root/$ bin/hbase shell |
| 68 | | |
| 69 | | * 4. hql > create table t1_table("person"); |
| 70 | | |
| 71 | | * 5. Come to Eclipse and run this code, and we will let database as that |
| 72 | | |
| 73 | | t1_table -> person |
| 74 | | |
| 75 | | ---------------- |
| 76 | | |
| 77 | | | name | locate | years | |
| 78 | | |
| 79 | | ---------------- |
| 80 | | |
| 81 | | | waue | taiwan | 1981 | |
| 82 | | |
| 83 | | ---------------- |
| 84 | | |
| 85 | | | shellon | taiwan | 1981 | |
| 86 | | |
| 87 | | * 6. Go to hbase console, type : hql > select * from t1_table; |
| 88 | | |
| 89 | | |
| 90 | | |
| 91 | | 08/06/06 12:20:48 INFO hbase.HTable: Creating scanner over t1_table starting at key |
| 92 | | |
| 93 | | +-------------------------+-------------------------+-------------------------+ |
| 94 | | |
| 95 | | | Row | Column | Cell | |
| 96 | | |
| 97 | | +-------------------------+-------------------------+-------------------------+ |
| 98 | | |
| 99 | | | 0 | person:locate | locate | |
| 100 | | |
| 101 | | +-------------------------+-------------------------+-------------------------+ |
| 102 | | |
| 103 | | | 0 | person:name | name | |
| 104 | | |
| 105 | | +-------------------------+-------------------------+-------------------------+ |
| 106 | | |
| 107 | | | 0 | person:years | years | |
| 108 | | |
| 109 | | +-------------------------+-------------------------+-------------------------+ |
| 110 | | |
| 111 | | | 19 | person:locate | taiwan | |
| 112 | | |
| 113 | | +-------------------------+-------------------------+-------------------------+ |
| 114 | | |
| 115 | | | 19 | person:name | waue | |
| 116 | | |
| 117 | | +-------------------------+-------------------------+-------------------------+ |
| 118 | | |
| 119 | | | 19 | person:years | 1981 | |
| 120 | | |
| 121 | | +-------------------------+-------------------------+-------------------------+ |
| 122 | | |
| 123 | | | 36 | person:locate | taiwan | |
| 124 | | |
| 125 | | +-------------------------+-------------------------+-------------------------+ |
| 126 | | |
| 127 | | | 36 | person:name | shellon | |
| 128 | | |
| 129 | | +-------------------------+-------------------------+-------------------------+ |
| 130 | | |
| 131 | | | 36 | person:years | 1981 | |
| 132 | | |
| 133 | | +-------------------------+-------------------------+-------------------------+ |
| 134 | | |
| 135 | | 3 row(s) in set. (0.04 sec) |
| 136 | | |
| 137 | | **/ |
| 138 | | |