欢迎来到天天文库
浏览记录
ID:26630747
大小:84.50 KB
页数:7页
时间:2018-11-28
《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=newLinkedList8、ing>>();ResultScannerscanner=null;//为分页创建的封装类对象,下面有给出具体属性TBDatatbData=null;try{//获取最大返回结果数量if(pageSize==null9、10、pageSize==0L)pageSize=100;if(currentPage==null11、12、currentPage==0)currentPage=1;//计算起始页和结束页IntegerfirstPage=
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=
此文档下载收益归作者所有