作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想在 java 中做这样的事情,就像我们在 hbase 中的 comparefilter 中所做的那样
hbase(main):003:0> import org.apache.hadoop.hbase.filter.CompareFilter
hbase(main):005:0> import org.apache.hadoop.hbase.filter.SubstringComparator
hbase(main):006:0> scan 'CUTOFF21', {FILTER => org.apache.hadoop.hbase.filter.RowFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'),SubstringComparator.new("C11\x09143662"))}
最佳答案
请参阅下面的 BinaryComparator
、RegexStringComparator
、SubstringComparator
示例,来自 here
Scan scan = new Scan();
scan.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col-1"));
Filter filter1 = new RowFilter(CompareFilter.CompareOp.LESS_OR_EQUAL, 1
new BinaryComparator(Bytes.toBytes("row-22")));
scan.setFilter(filter1);
ResultScanner scanner1 = table.getScanner(scan);
for (Result res : scanner1) {
System.out.println(res);
}
scanner1.close();
Filter filter2 = new RowFilter(CompareFilter.CompareOp.EQUAL, 2
new RegexStringComparator(".*-.5"));
scan.setFilter(filter2);
ResultScanner scanner2 = table.getScanner(scan);
for (Result res : scanner2) {
System.out.println(res);
}
scanner2.close();
Filter filter3 = new RowFilter(CompareFilter.CompareOp.EQUAL, 3
new SubstringComparator("-5"));
scan.setFilter(filter3);
ResultScanner scanner3 = table.getScanner(scan);
for (Result res : scanner3) {
System.out.println(res);
}
scanner3.close();
你的情况是这样的
Filter filter3 = new RowFilter(CompareFilter.CompareOp.EQUAL, 3
new SubstringComparator("C11\x09143662"));
scan.setFilter(filter3);
ResultScanner scanner3 = table.getScanner(scan);
for (Result res : scanner3) {
System.out.println(res);
}
scanner3.close();
关于java - java实现hbase的compareFilter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41887937/
我们可以根据输入值取 compareOperator 值吗?例如,如果我的输入是 eq,那么它应该选择 CompareFilter.CompareOp.EQUAL,否则如果输入是 ne,它应该选择 C
我是一名优秀的程序员,十分优秀!