Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Client;
- import java.io.IOException;
- import java.util.List;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.hbase.HBaseConfiguration;
- import org.apache.hadoop.hbase.client.Scan;
- import org.apache.hadoop.hbase.client.coprocessor.AggregationClient;
- import org.apache.hadoop.hbase.coprocessor.AggregateProtocol;
- import org.apache.hadoop.hbase.coprocessor.ColumnInterpreter;
- import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
- import org.apache.hadoop.hbase.filter.FilterList;
- import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
- import org.apache.hadoop.hbase.ipc.ProtocolSignature;
- import org.apache.hadoop.hbase.thrift.generated.Hbase.get_args;
- import org.apache.hadoop.hbase.util.Bytes;
- import org.apache.hadoop.hbase.util.Pair;
- public class MyAggregationClient {
- /**
- * @param args
- */
- private static final byte[] TABLE_NAME = Bytes.toBytes("mytable");
- private static final byte[] CF = Bytes.toBytes("d");
- private static final byte[] Column = Bytes.toBytes("xxx");
- public static void main(String[] args) throws Throwable {
- // TODO Auto-generated method stub
- Configuration customConf = new Configuration();
- customConf.setStrings("hbase.zookeeper.quorum",
- "node0,node1,node2");
- // Increase RPC timeout, in case of a slow computation
- customConf.setLong("hbase.rpc.timeout", 600000);
- // Default is 1, set to a higher value for faster scanner.next(..)
- customConf.setLong("hbase.client.scanner.caching", 1000);
- Configuration configuration = HBaseConfiguration.create(customConf);
- AggregationClient aggregationClient = new AggregationClient(
- configuration);
- Scan scan = new Scan();
- scan.addFamily(CF);
- FilterList list = new FilterList(FilterList.Operator.MUST_PASS_ONE);
- SingleColumnValueFilter filter1 = new SingleColumnValueFilter(
- CF,
- Column,
- CompareOp.EQUAL,
- Bytes.toBytes("my value")
- );
- list.addFilter(filter1);
- /*
- SingleColumnValueFilter filter2 = new SingleColumnValueFilter(
- CF,
- column,
- CompareOp.EQUAL,
- Bytes.toBytes("my other value")
- );
- list.add(filter2);
- */
- scan.setFilter(list);
- long rowCount = aggregationClient.rowCount(TABLE_NAME, null, scan);
- System.out.println("row count is " + rowCount);
- String cell;
- long row;
- String c;
- ColumnInterpreter<double, double> ci;
- AggregateProtocol agg ;
- long rowcount = agg.getRowNum(ci, scan);
- double sum = aggregationClient.avg(TABLE_NAME, null, scan);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement