立即注册 登录
About云-梭伦科技 返回首页

baber的个人空间 https://www.aboutyun.com/?29411 [收藏] [复制] [分享] [RSS]

日志

Hbase协处理器之EenPoint

已有 942 次阅读2016-3-23 16:57 |个人分类:大数据相关| 协处理器

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     命令去执行


路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

关闭

推荐上一条 /2 下一条