java实现hbase分页,实现Hbase的分页

做一个项目中由于

1.启动全局aggregation,能过操纵所有的表上的数据。通过修改hbase-site.xml这个文件来实现,只需要添加如下

hbase.coprocessor.user.region.classes <

2.启用表aggregation,只对特定的表生效。通过

(1)disable指定表。hbase> disable ‘my

(2)添加aggregation hbase> alter ‘mytable’, METHOD => ‘table_att’,’coprocessor’=>’|org.apache.hadoop.hbase.coprocessor.AggregateImplementation||’

(3)重启指定表 hbase> enable ‘mytable’

Hbase客户端调用代码示例

1、 得到hbase的表结构总数

public int getTotalRecord(Table

2 ,实现分页

public MapgetIndexTableInfo(Table table,String tableName, String nowTime,String s communtiyKeysMap=new TreeMap(); ResultScanner scanner= null;//为分页创建的封装类对象,下面有给出具体属性 try{//获取最大返回结果数量 if (pageSize == null || pageSize == 0L) pageSize= 100;if (currentPage == null || currentPage == 0) currentPage= 1;//计算起始页和结束页 Integer nowPageSize=pageSize+1;//MUST_PASS_ALL(条件 AND) MUST_PASS_ONE(条件OR) FilterList filterList = newFilterList(FilterList.Operator.MUST_PASS_ALL); Filter filter1=newPageFilter(nowPageSize); filterList.addFilter(filter1);//if(tableName.equals("COMMUNITY_KEYS_INDEX")){//Filter filter2 = new QualifierFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("communitykey")));//filterList.addFilter(filter2);//} Scan scan = newScan(); scan.setFilter(filterList); scan.setMaxResultSize(nowPageSize); scan.setStartRow(Bytes.toBytes(startRow));if(!nowTime.equals("")){ scan.setStopRow(nowTime.getBytes()); } scanner=table.getScanner(scan);int i = 1;// for(Result result : scanner) { String row=newString(result.getRow());for(Cell cell : result.rawCells()) {//System.out.println("列族:"+new String(CellUtil.cloneQualifier(cell))+">>>"+new String(CellUtil.cloneValue(cell))); if(i==nowPageSize){ communtiyKeysMap.put("nextStart", row.substring(0,row.lastIndexOf(":")));break; } communtiyKeysMap.put(row,newString(CellUtil.cloneValue(cell))); } i++; } }catch(IOException e) { e.printStackTrace(); }{if (scanner != null) scanner.close(); }returncommuntiyKeysMap; }

3,该分页中处理和跳转下一页

for(int page=1;page<=pageNum;page++){ //分页 List pageList = new ArrayList(); //子类调用具体分析//1.查出要分析的数据 Map communtiyKeysMap=getIndexTableInfo(hTable,hbaseIndexTabel,nowTime,startRow,page,pageSize);for(String communitykey:communtiyKeysMap.keySet()){ String rowKeyIndex=communitykey; String cellValue=communtiyKeysMap.get(rowKeyIndex);if(communitykey.equals("nextStart")){ startRow=cellValue;continue; //下一页进行跳转 } }//实现调用具体的分析//实现该分页处理 }

该过程总共为三步,1.设置表的协处理器 Aggregation,使表能够实现

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值