20,808
社区成员
发帖
与我相关
我的任务
分享
/**
* Hello world!
*/
public class PageFilterExample {
public static void main(String[] args) throws IOException {
Configuration config = HBaseConfiguration.create();
config.set("hbase.zookeeper.quorum", "QT-H-0038");
String tableName = "testTable";
String cfName = "colfam1";
final byte[] POSTFIX = new byte[] { 0x00 };
HTable table = new HTable(config, tableName);
Filter filter = new PageFilter(15);
byte[] lastRow = null;
int totalRows = 0;
while (true) {
Scan scan = new Scan();
scan.setFilter(filter);
if(lastRow != null){
//注意这里添加了POSTFIX操作,不然死循环了
byte[] startRow = Bytes.add(lastRow,POSTFIX);
scan.setStartRow(startRow);
}
ResultScanner scanner = table.getScanner(scan);
int localRows = 0;
Result result;
while((result = scanner.next()) != null){
System.out.println(localRows++ + ":" + result);
totalRows ++;
lastRow = result.getRow();
}
scanner.close();
if(localRows == 0) break;
}
System.out.println("total rows:" + totalRows);
}
}