检查HBase表中是否存在值



我有一个HBase表,其数据如下所示:

key1 c:hasErrors false
key2 c:hasErrors true
key3 c:hasErrors false

我想检查列限定符hasErrors是否具有true表中任何位置的值。

显然我可以进行扫描:

Scan scan = new Scan();
scan.addColumn(colFam, colQual);
Filter filter = new SingleColumnValueFilter(colFam, colQual, CompareFilter.CompareOp.EQUAL,
new BinaryComparator(Bytes.toBytes("true")));
scan.setFilter(filter);
ResultScanner results = table.scan(scan, auditTableName);

但这是不可取的,因为任何匹配的行都会被拉回我的应用程序,我必须检查是否results.next() != false.

有没有办法只返回一个布尔值,告诉我该值是否至少存在于一行中?

看看

org.apache.hadoop.hbase.filter.SingleColumnValueFilter
/**
* Set whether entire row should be filtered if column is not found.
* 
* If true, the entire row will be skipped if the column is not found.
* 
* If false, the row will pass if the column is not found.  This is default.
* @param filterIfMissing flag
*/
public void setFilterIfMissing(boolean filterIfMissing) {
this.filterIfMissing = filterIfMissing;
}

根据文档,它不会返回不匹配的行。

附言如果使用 Get,则setCheckExistenceOnly方法可用于类似目的

相关内容

最新更新