Advertisement
Guest User

Column Interpreter

a guest
Nov 11th, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. package Client;
  2.  
  3. import java.io.IOException;
  4. import java.util.List;
  5.  
  6. import org.apache.hadoop.conf.Configuration;
  7. import org.apache.hadoop.hbase.HBaseConfiguration;
  8. import org.apache.hadoop.hbase.client.Scan;
  9. import org.apache.hadoop.hbase.client.coprocessor.AggregationClient;
  10. import org.apache.hadoop.hbase.coprocessor.AggregateProtocol;
  11. import org.apache.hadoop.hbase.coprocessor.ColumnInterpreter;
  12. import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
  13. import org.apache.hadoop.hbase.filter.FilterList;
  14. import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
  15. import org.apache.hadoop.hbase.ipc.ProtocolSignature;
  16. import org.apache.hadoop.hbase.thrift.generated.Hbase.get_args;
  17. import org.apache.hadoop.hbase.util.Bytes;
  18. import org.apache.hadoop.hbase.util.Pair;
  19.  
  20. public class MyAggregationClient {
  21.  
  22. /**
  23. * @param args
  24. */
  25. private static final byte[] TABLE_NAME = Bytes.toBytes("mytable");
  26. private static final byte[] CF = Bytes.toBytes("d");
  27. private static final byte[] Column = Bytes.toBytes("xxx");
  28.  
  29. public static void main(String[] args) throws Throwable {
  30. // TODO Auto-generated method stub
  31.  
  32. Configuration customConf = new Configuration();
  33. customConf.setStrings("hbase.zookeeper.quorum",
  34. "node0,node1,node2");
  35. // Increase RPC timeout, in case of a slow computation
  36. customConf.setLong("hbase.rpc.timeout", 600000);
  37. // Default is 1, set to a higher value for faster scanner.next(..)
  38. customConf.setLong("hbase.client.scanner.caching", 1000);
  39. Configuration configuration = HBaseConfiguration.create(customConf);
  40. AggregationClient aggregationClient = new AggregationClient(
  41. configuration);
  42. Scan scan = new Scan();
  43. scan.addFamily(CF);
  44. FilterList list = new FilterList(FilterList.Operator.MUST_PASS_ONE);
  45. SingleColumnValueFilter filter1 = new SingleColumnValueFilter(
  46. CF,
  47. Column,
  48. CompareOp.EQUAL,
  49. Bytes.toBytes("my value")
  50. );
  51. list.addFilter(filter1);
  52.  
  53. /*
  54. SingleColumnValueFilter filter2 = new SingleColumnValueFilter(
  55. CF,
  56. column,
  57. CompareOp.EQUAL,
  58. Bytes.toBytes("my other value")
  59. );
  60. list.add(filter2);
  61. */
  62. scan.setFilter(list);
  63.  
  64. long rowCount = aggregationClient.rowCount(TABLE_NAME, null, scan);
  65. System.out.println("row count is " + rowCount);
  66.  
  67. String cell;
  68. long row;
  69. String c;
  70. ColumnInterpreter<double, double> ci;
  71.  
  72. AggregateProtocol agg ;
  73. long rowcount = agg.getRowNum(ci, scan);
  74.  
  75. double sum = aggregationClient.avg(TABLE_NAME, null, scan);
  76. }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement