检查 HBase 中是否存在值 table

Check whether a value exists in an HBase table

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

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

我想检查列限定符 hasErrors 在 table 中的任何位置是否具有值 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;
}

根据文档,它不会 return 行不匹配。

P.S。如果你使用 Get,你有 setCheckExistenceOnly 用于类似目的的方法