【发布时间】:2016-09-27 00:35:03
【问题描述】:
我想根据特定列中的值列表过滤 Hbase 表扫描。
例如:对于下面给出的表 Employee,我想获取 ID 在 (123,789) 中的员工的记录。
ROW COLUMN+CELL
row1 column=emp:name, timestamp=1321296699190, value=TestName1
row1 column=emp:id, timestamp=1321296715892, value=123
row2 column=emp:name, timestamp=1321296699190, value=TestName2
row2 column=emp:id, timestamp=1321296715892, value=456
row3 column=emp:name, timestamp=1321296699190, value=TestName3
row3 column=emp:id, timestamp=1321296715892, value=789
row4 column=emp:name, timestamp=1321296699190, value=TestName4
row4 column=emp:id, timestamp=1321296715892, value=101
row5 column=emp:name, timestamp=1321296699190, value=TestName5
row5 column=emp:id, timestamp=1321296715892, value=102
我尝试使用SingleColumnValueFilter,但它只从表中获取一条记录。下面给出的是我的代码。请让我知道我哪里出错了:
HTableInterface empTableObj = service.openTable("employee");;
Scan scan = new Scan(startRow, endRow);
FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE);
Integer[] idArray = {123, 789};
for(int i=0;i<idArray.length;i++){
SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes.toBytes("emp"), Bytes.toBytes("id"), CompareOp.EQUAL, Bytes.toBytes(idArray[i].toString()));
filterList.addFilter(filter);
}
scan.setFilter(filterList);
ResultScanner rs = empTableObj.getScanner(scan);
谢谢
【问题讨论】:
-
可能不会有太大的不同,您可以尝试 Scan scan = new Scan() 然后显式设置开始和停止行。 public Scan setStartRow(byte[] startRow) 和 public Scan setStopRow(byte[] stopRow)
标签: hbase