Advertisement
Guest User

TestAggregateSum

a guest
May 7th, 2012
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. package com.intuit.ihub.hbase.poc.aggregation;
  2.  
  3. import org.apache.hadoop.conf.Configuration;
  4. import org.apache.hadoop.hbase.HBaseConfiguration;
  5. import org.apache.hadoop.hbase.client.Scan;
  6. import org.apache.hadoop.hbase.client.coprocessor.AggregationClient;
  7. import org.apache.hadoop.hbase.coprocessor.ColumnInterpreter;
  8. import org.apache.hadoop.hbase.filter.Filter;
  9. import org.apache.hadoop.hbase.filter.PrefixFilter;
  10. import org.apache.hadoop.hbase.util.Bytes;
  11.  
  12. import com.intuit.ihub.hbase.poc.aggregation.interpreter.DoubleColumnInterpreter;
  13.  
  14. public class TransactionAmountSum {
  15.    
  16.     private static Configuration conf =  HBaseConfiguration.create();
  17.    
  18.                 public static void doAggregation(String prefix, String endRow, String tableName)
  19.                 {
  20.                 System.out.println("Setting: hbase.coprocessor.region.classes ");
  21.                 conf.set("hbase.coprocessor.region.classes", "org.apache.hadoop.hbase.coprocessor.AggregateImplementation");
  22.                 AggregationClient aClient = new AggregationClient(conf);
  23.                 Filter filter = new PrefixFilter(Bytes.toBytes(prefix));
  24.                 Scan scan = new Scan();
  25.                 scan.addColumn(Bytes.toBytes("t"), Bytes.toBytes("amt"));
  26.                 scan.setStartRow(Bytes.toBytes(prefix));
  27.                 scan.setStopRow(Bytes.toBytes(endRow));  
  28.                 ColumnInterpreter<Double,Double> ci = new DoubleColumnInterpreter(); // this is //my custom Custom Column Interpreter
  29.                 try {
  30.                     long rowCount = aClient.rowCount(Bytes.toBytes(tableName), ci, scan);
  31.                     double sum = aClient.sum(Bytes.toBytes(tableName), ci, scan);
  32.                    
  33.                     System.out.print("Sum is:" + sum);
  34.                     System.out.print("rowcount is:" + sum);
  35.                 } catch (Throwable e) {
  36.                     // TODO Auto-generated catch block
  37.                     e.printStackTrace();
  38.                 }
  39.                 }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement