简体   繁体   English

带有偏移量的Hbase扫描

[英]Hbase scan with offset

Is there a way to scan a HBase table getting, for example, the first 100 results, then later get the next 100 and so on... Just like in SQL we do with LIMIT and OFFSET? 有没有一种方法可以扫描HBase表,例如获取前100个结果,然后再获取下100个结果,依此类推...就像在SQL中一样,我们对LIMIT和OFFSET进行处理? My row keys are uuid 我的行键是uuid

You can do it multiple ways. 您可以通过多种方式进行操作。 The easiest one is a page filter. 最简单的一种是页面过滤器。 Below is the code example from HBase: The Definitive Guide , page 150. 以下是HBase的代码示例:权威指南 ,第150页。

private static final byte[] POSTFIX = new byte[] { 0x00 };
Filter filter = new PageFilter(15);
int totalRows = 0; byte[] lastRow = null; 
while (true) {
  Scan scan = new Scan(); 
  scan.setFilter(filter); 
  if (lastRow != null) {
    byte[] startRow = Bytes.add(lastRow, POSTFIX); 
    System.out.println("start row: " + Bytes.toStringBinary(startRow)); 
    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);

Or you can set catching on scan for the limit you want and then change the start row to the last row + 1 from the prev scan for every get. 或者,您可以将扫描限制设置为所需的限制,然后将每次获取的起始行更改为上一次扫描的最后一行+ 1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM