hbase分页查询实现

hbase分页查询实现

ID:26630747

大小:84.50 KB

页数:7页

时间:2018-11-28

hbase分页查询实现_第1页
hbase分页查询实现_第2页
hbase分页查询实现_第3页
hbase分页查询实现_第4页
hbase分页查询实现_第5页
资源描述:

《hbase分页查询实现》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、hbase分页查询实现Hbase本身是没有分页查询的,我在网上找了很多资料来实现一个分页功能,在这里做了一下记录,分享给大家,有什么不足之处,请尽管指出。废话不多说,看代码。importjava.io.IOException;importjava.util.LinkedHashMap;importjava.util.LinkedList;importjava.util.List;importjava.util.Map;importorg.apache.commons.lang.StringUtils;im

2、portorg.apache.hadoop.conf.Configuration;importorg.apache.hadoop.hbase.HBaseConfiguration;importorg.apache.hadoop.hbase.client.Get;importorg.apache.hadoop.hbase.client.HTableInterface;importorg.apache.hadoop.hbase.client.HTablePool;importorg.apache.hadoop

3、.hbase.client.Result;importorg.apache.hadoop.hbase.client.ResultScanner;importorg.apache.hadoop.hbase.client.Scan;importorg.apache.hadoop.hbase.filter.CompareFilter.CompareOp;importorg.apache.hadoop.hbase.filter.Filter;importorg.apache.hadoop.hbase.filter

4、.FilterList;importorg.apache.hadoop.hbase.filter.FirstKeyOnlyFilter;importorg.apache.hadoop.hbase.filter.SingleColumnValueFilter;importorg.apache.hadoop.hbase.util.Bytes;publicclassHBaseUtils{privatestaticConfigurationconfig=null;privatestaticHTablePooltp

5、=null;static{//加载集群配置config=HBaseConfiguration.create();config.set("hbase.zookeeper.quorum","xx.xx.xx");config.set("hbase.zookeeper.property.clientPort","2181");//创建表池(可伟略提高查询性能,具体说明请百度或官方API)tp=newHTablePool(config,10);}/**获取hbase的表*/publicstaticHTableIn

6、terfacegetTable(StringtableName){if(StringUtils.isEmpty(tableName))returnnull;returntp.getTable(getBytes(tableName));}/*转换byte数组*/publicstaticbyte[]getBytes(Stringstr){if(str==null)str="";returnBytes.toBytes(str);}/***查询数据*@paramtableKey表标识*@paramqueryKey

7、查询标识*@paramstartRow开始行*@paramparamsMap参数集合*@return结果集*/publicstaticTBDatagetDataMap(StringtableName,StringstartRow,StringstopRow,IntegercurrentPage,IntegerpageSize)throwsIOException{List>mapList=null;mapList=newLinkedList

8、ing>>();ResultScannerscanner=null;//为分页创建的封装类对象,下面有给出具体属性TBDatatbData=null;try{//获取最大返回结果数量if(pageSize==null

9、

10、pageSize==0L)pageSize=100;if(currentPage==null

11、

12、currentPage==0)currentPage=1;//计算起始页和结束页IntegerfirstPage=

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。