首页 > 解决方案 > 检查 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.

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

标签: javahadoophbase

解决方案


看一眼

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;
}

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

PS如果你使用Get,你有setCheckExistenceOnly类似目的的方法


推荐阅读