如何根据两列的范围查询HBase?
How to query HBase based on two columns' ranges?
我有一个 HBase table,其架构如下:
行键、col1、col2、col3
我想根据两列的范围查询 table,例如:
1000 < 行键 < 1000000 和
200 < co1 < 300
我该怎么做?我注意到 Java API 提供了只能过滤一列的 MultiRowRangeFilter,但我想根据范围过滤两列。有人有什么想法吗?提前谢谢你。
按1行键范围和1列范围查询时,MultiRowRangeFilter
不适用,因为它是过滤多个行键范围,例如
100 < rowKey < 200 AND 1500 < rowKey < 2000
您想在 FilterList
为 2 SingleColumnValueFilter
的行键上使用 Scan
。
byte[] keyStart = Bytes.toBytes(1000);
byte[] keyEnd = Bytes.toBytes(1000000);
byte[] columnMin = Bytes.toBytes(200);
byte[] columnMax = Bytes.toBytes(300);
byte[] cf = Bytes.toBytes(familyName)
byte[] column = Bytes.toBytes(columnNameToBeFiltered)
Scan scan = new Scan(keyStart, keyEnd);
FilterList list = new FilterList(FilterList.Operator.MUST_PASS_ALL);
SingleColumnValueFilter filter1 = new SingleColumnValueFilter(
cf, column, CompareOp.GREATER, columnMin);
list.add(filter1);
SingleColumnValueFilter filter2 = new SingleColumnValueFilter(
cf, column, CompareOp.LESS, columnMax);
list.add(filter2);
scan.setFilter(list);
ResultScanner scanner = table.getScanner(scan);
...//parsing result
我有一个 HBase table,其架构如下:
行键、col1、col2、col3
我想根据两列的范围查询 table,例如:
1000 < 行键 < 1000000 和 200 < co1 < 300
我该怎么做?我注意到 Java API 提供了只能过滤一列的 MultiRowRangeFilter,但我想根据范围过滤两列。有人有什么想法吗?提前谢谢你。
按1行键范围和1列范围查询时,MultiRowRangeFilter
不适用,因为它是过滤多个行键范围,例如
100 < rowKey < 200 AND 1500 < rowKey < 2000
您想在 FilterList
为 2 SingleColumnValueFilter
的行键上使用 Scan
。
byte[] keyStart = Bytes.toBytes(1000);
byte[] keyEnd = Bytes.toBytes(1000000);
byte[] columnMin = Bytes.toBytes(200);
byte[] columnMax = Bytes.toBytes(300);
byte[] cf = Bytes.toBytes(familyName)
byte[] column = Bytes.toBytes(columnNameToBeFiltered)
Scan scan = new Scan(keyStart, keyEnd);
FilterList list = new FilterList(FilterList.Operator.MUST_PASS_ALL);
SingleColumnValueFilter filter1 = new SingleColumnValueFilter(
cf, column, CompareOp.GREATER, columnMin);
list.add(filter1);
SingleColumnValueFilter filter2 = new SingleColumnValueFilter(
cf, column, CompareOp.LESS, columnMax);
list.add(filter2);
scan.setFilter(list);
ResultScanner scanner = table.getScanner(scan);
...//parsing result