java - 检查 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;
}
根据文档,它不会返回不匹配的行。
PS如果你使用Get,你有setCheckExistenceOnly
类似目的的方法
推荐阅读
- html - 如何修复'我无法从函数获取值到 .html
- python - 如何在 python 中对其他列的数据框列求和?
- angular - 无法在“文档”上执行“querySelector”
- jquery - 即使数据以 json 格式正确返回,Jquery 自动完成也不显示列表
- sql - 添加新行并将行显示为 SQL Server 中的列时如何自动获取行数
- reactjs - How to implement forgot password page on react-admin
- r - 使用 rvest 进行网页抓取
- git - 如何强制 git gui 的图形密码提示框?
- php - 如何使用 PHP Curl 修复“请启用 cookie”Cloudflare 错误
- android - Flutter 检索 ro.product.cpu.abi 的设备属性时出错