Search code examples
javahbasebyteprecision

Why Bytes.toBytes() in HBase cannot return last row I search in my case?


I use Bytes.toBytes() to set the range for Scan, and if I input the stumber = "AAAA00000", the results are "AAAA000000" ~ "AAAA000008", why "AAAA000009" does not be included?

for (String stumber : stumbersArr) {
    byte[] startRow = Bytes.toBytes(stumber + "0");
    byte[] endRow = Bytes.toBytes(stumber + "9");

    Scan scan = new Scan(startRow, endRow);

    Filter filter1 = new RowFilter(CompareFilter.CompareOp.EQUAL, new SubstringComparator(stumber));

    scan.setFilter(filter1);
    scan.setMaxVersions(versions);

    ResultScanner scanner1 = table.getScanner(scan);
    Cell[] cells;
    for (Result res : scanner1) {
        cells = res.rawCells();
        list.addAll(getHBaseTableDataListFromCells(cells));
    }
}

Solution

  • Because the end boundary is exclusive, see documentation about scan.