Changes between Version 1 and Version 2 of NCHCCloudCourse100929_4_HBEX3


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

--

Legend:

Unmodified
Added
Removed
Modified
  • NCHCCloudCourse100929_4_HBEX3

    v1 v2  
    1414{{{
    1515#!java
     16
    1617package org.nchc.hbase;
    1718
     
    2829public class GetColumn {
    2930
    30         static String getColumn(String tablename, String row, String family,
    31                         String column) {
    32                 HBaseConfiguration conf = new HBaseConfiguration();
    33                 String ret = "";
     31  static String getColumn(String tablename, String row, String family,
     32      String column) {
     33    HBaseConfiguration conf = new HBaseConfiguration();
     34    String ret = "";
    3435
    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)));
     36    HTable table;
     37    try {
     38      table = new HTable(conf, Bytes.toBytes(tablename));
     39      Get g = new Get(Bytes.toBytes(row));
     40      Result rowResult = table.get(g);
     41      ret = Bytes.toString(rowResult.getValue(Bytes.toBytes(family + ":"
     42          + column)));
    4243
    43                         table.close();
    44                 } catch (IOException e) {
     44      table.close();
     45    } catch (IOException e) {
    4546
    46                         e.printStackTrace();
    47                 }
     47      e.printStackTrace();
     48    }
    4849
    49                 return ret;
    50         }
     50    return ret;
     51  }
    5152
    52         public static void main(String[] argv) {
     53  public static void main(String[] argv) {
     54            // eclipse only
     55//          String[] arg = {"ex1Table", "row221", "Detail", "c1"};
     56//          argv = arg;
    5357
    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         }
     58    String[] args = new GenericOptionsParser(new Configuration(), argv)
     59        .getRemainingArgs();
     60    if (args.length < 4) {
     61      System.out.println("GetColumn <TableName> <Row> <Family> <Qualifier> ");
     62      return;
     63    }
     64    System.out.println(getColumn(args[0], args[1], args[2], args[3]));
     65  }
    6266}
    6367