hbase rowkey 实现分页

  • Post author:
  • Post category:其他


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(sc



版权声明:本文为chenaini119原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。