hbase rowkey 实现分页

hbase 是根据rowkey查询的,ScanRows prefixFilter等过滤
要实现分页只能从rowkey下手
rowkey生成规则
rowkey = (mall_id%100)(mall_id)(biz_type)(date)(row_number)

row_number 从 00001 到010001这样下去 我们拿count只需要反向拿到最后一条解析下rowkey
分页根据 page pagesize 计算 startRowkey endRowKey

 @Override
    public List<Map<String, String>> queryOneByRowPrefixAndReversed(String tableName, String prefix, Boolean isReversed) throws IOException {
        Scan scan = generatePrefixScan(prefix);
        FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
        Filter pageFilter = new PageFilter(1);
        filterList.addFilter(pageFilter);
        scan.setFilter(filterList);
        scan.setReversed(isReversed);
        if (isReversed) {
            byte[] startRow = scan.getStartRow();
            scan.setStartRow(scan.getStopRow());
            scan.setStopRow(startRow);
        }
        return getScanResult(scan, tableName, "queryByRowPrefixAndReversed");
    }

    @Override
    public List<Map<String, String>> queryByStartRowAndEndRowPrefix(String tableName, String startRowKey, String endRowKey) throws IOException {
        Scan scan = new Scan();
        FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
        Filter startRowFilter = new RowFilter(CompareFilter.CompareOp.GREATER, new BinaryComparator(Bytes.toBytes(startRowKey)));
        Filter endRowFilter = new RowFilter(CompareFilter.CompareOp.LESS_OR_EQUAL, new BinaryComparator(Bytes.toBytes(endRowKey)));
        filterList.addFilter(startRowFilter);
        filterList.addFilter(endRowFilter);
        scan.setFilter(filterList);
        return getScanResult(scan, tableName, "queryByStartRowAndEndRowPrefix");
    }
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页