資源描述:
《hbase分頁查詢實(shí)現(xiàn)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、hbase分頁查詢實(shí)現(xiàn)Hbase本身是沒有分頁查詢的,我在網(wǎng)上找了很多資料來實(shí)現(xiàn)一個(gè)分頁功能,在這里做了一下記錄,分享給大家,有什么不足之處,請(qǐng)盡管指出。廢話不多說,看代碼。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");//創(chuàng)建表池(可偉略提高查詢性能,具體說明請(qǐng)百度或官方API)tp=newHTablePool(config,10);}/**獲取hbase的表*/publicstaticHTableIn
6、terfacegetTable(StringtableName){if(StringUtils.isEmpty(tableName))returnnull;returntp.getTable(getBytes(tableName));}/*轉(zhuǎn)換byte數(shù)組*/publicstaticbyte[]getBytes(Stringstr){if(str==null)str="";returnBytes.toBytes(str);}/***查詢數(shù)據(jù)*@paramtableKey表標(biāo)識(shí)*@paramqueryKey
7、查詢標(biāo)識(shí)*@paramstartRow開始行*@paramparamsMap參數(shù)集合*@return結(jié)果集*/publicstaticTBDatagetDataMap(StringtableName,StringstartRow,StringstopRow,IntegercurrentPage,IntegerpageSize)throwsIOException{List