gpt4 book ai didi

java - java实现hbase的compareFilter

转载 作者:可可西里 更新时间:2023-11-01 16:40:28 25 4
gpt4 key购买 nike

我想在 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"))}

最佳答案

请参阅下面的 BinaryComparatorRegexStringComparatorSubstringComparator 示例,来自 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com