package hbase.endpoint;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.coprocessor.AggregationClient;
import org.apache.hadoop.hbase.client.coprocessor.LongColumnInterpreter;
public class MyAggregationClient {
public static void main(String[] args) throws Throwable {
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum",
"192.168.201.2");
//提高RPC通信时长
//conf.setLong("hbase.rpc.timeout", 600000);
//设置Scan缓存
//conf.setLong("hbase.client.scanner.caching", 1000);
//解释器类型,说白了,返回类型
LongColumnInterpreter columnInterpreter = new LongColumnInterpreter();
//RPC客户端
AggregationClient aggregationClient = new AggregationClient(conf);
//扫描器
Scan scan = new Scan();
//指定扫描列族
//scan.addFamily(Bytes.toBytes("c1"));
//指定扫描列
///scan.addColumn(Bytes.toBytes("c1"), Bytes.toBytes("eug"));
long rowCount = aggregationClient.rowCount(
TableName.valueOf("japi"),
columnInterpreter,
scan);
System.out.println("row count is " + rowCount);
}
}
这个协处理器类似存储过程,自主调度。
进入hbase shell
hbase(main):071:0> disable 'japi'
0 row(s) in 1.6730 seconds
hbase(main):074:0> alter 'japi',
hbase(main):075:0*
hbase(main):076:0* METHOD => 'table_att','coprocessor'=>'|org.apache.hadoop.hbase.coprocessor.AggregateImplementation||'
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 1.6850 seconds
hbase(main):077:0> enable 'japi'
如果你是在windows环境下,eclipse有集成hadoop可以直接运行
也可以打成jar包放到hbase的lib目录下
hbase hbase.endpoint.MyAggregationClient 命令去执行