Changes between Initial Version and Version 1 of NCHCCloudCourse100929_4_HBEX3


Ignore:
Timestamp:
Sep 27, 2010, 6:26:28 PM (14 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NCHCCloudCourse100929_4_HBEX3

    v1 v1  
     1{{{
     2#!html
     3<div style="text-align: center; color:#151B8D"><big style="font-weight: bold;"><big><big>
     4HBase 進階課程
     5</big></big></big></div> <div style="text-align: center; color:#7E2217"><big style="font-weight: bold;"><big>
     6程式範例練習
     7</big></big></div>
     8}}}
     9
     10[wiki:NCHCCloudCourse100929_4_HBEX2 上一關 < ] 第三關 [wiki:NCHCCloudCourse100929_4_HBEX4 > 下一關]
     11
     12 = 範例三: Get Column Value =
     13
     14{{{
     15#!java
     16package org.nchc.hbase;
     17
     18import java.io.IOException;
     19
     20import org.apache.hadoop.conf.Configuration;
     21import org.apache.hadoop.hbase.HBaseConfiguration;
     22import org.apache.hadoop.hbase.client.Get;
     23import org.apache.hadoop.hbase.client.HTable;
     24import org.apache.hadoop.hbase.client.Result;
     25import org.apache.hadoop.hbase.util.Bytes;
     26import org.apache.hadoop.util.GenericOptionsParser;
     27
     28public class GetColumn {
     29
     30        static String getColumn(String tablename, String row, String family,
     31                        String column) {
     32                HBaseConfiguration conf = new HBaseConfiguration();
     33                String ret = "";
     34
     35                HTable table;
     36                try {
     37                        table = new HTable(conf, Bytes.toBytes(tablename));
     38                        Get g = new Get(Bytes.toBytes(row));
     39                        Result rowResult = table.get(g);
     40                        ret = Bytes.toString(rowResult.getValue(Bytes.toBytes(family + ":"
     41                                        + column)));
     42
     43                        table.close();
     44                } catch (IOException e) {
     45
     46                        e.printStackTrace();
     47                }
     48
     49                return ret;
     50        }
     51
     52        public static void main(String[] argv) {
     53
     54                String[] args = new GenericOptionsParser(new Configuration(), argv)
     55                                .getRemainingArgs();
     56                if (args.length < 4) {
     57                        System.out.println("GetColumn <TableName> <Row> <Family> <Qualifier> ");
     58                        return;
     59                }
     60                System.out.println(getColumn(args[0], args[1], args[2], args[3]));
     61        }
     62}
     63
     64}}}
     65
     66