在我的应用程序中,我需要从Hbase获取数据,我需要对该数据应用过滤器,我需要对要获取的记录数量进行限制。以下是我写的代码:
ResultScanner scanner = null;
HTable table = null;
Configuration config = HBaseConfiguration.create();
config.set("hbase.zookeeper.quorum", hbaseServer);
config.set("hbase.zookeeper.property.clientPort", hbasePort);
FilterList list = new FilterList(FilterList.Operator.MUST_PASS_ALL);
table = new HTable(config, "TableName");
SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes.toBytes("ColumnName"),
Bytes.toBytes("ColumnName"), CompareFilter.CompareOp.EQUAL,
new BinaryComparator(Bytes.toBytes(String.valueOf("FilterValue"))));
SingleColumnValueFilter filter1 = new SingleColumnValueFilter(Bytes.toBytes("ColumnName2"),
Bytes.toBytes("ColumnName2"), CompareFilter.CompareOp.EQUAL,
new BinaryComparator(Bytes.toBytes(String.valueOf("FilterValue2"))));
list.addFilter(filter);
list.addFilter(filter1);
Scan scan = new Scan();
scan.setFilter(list);
scan.setFilter(new PageFilter(10));
scanner = table.getScanner(scan);
过滤器工作得很好,但我得到了完整的数据集。 scan.setFilter(new PageFilter(10))无效。我只需要提取与提供的过滤器匹配的前10条记录。我也尝试过:
scan.setMaxResultSize(10);
scan.setMaxResultsPerColumnFamily(10);
但这些都不起作用。上面的代码会出现什么问题?
答案 0 :(得分:0)
如果您正确复制了代码,则会重写第一个过滤器:
Scan scan = new Scan();
scan.setFilter(list);
scan.setFilter(new PageFilter(10)); <-- changes FilterList to PageFilter
似乎你想要做
list.addFilter(new PageFilter(10));