use of org.apache.hadoop.hbase.filter.FuzzyRowFilter in project java-bigtable-hbase by googleapis.
the class AbstractTestFilters method testFuzzyWithIntKeys.
@Test
public void testFuzzyWithIntKeys() throws Exception {
Table table = getDefaultTable();
List<byte[]> keys = Collections.unmodifiableList(Arrays.asList(createKey(5, 10, 126, 5), createKey(5, 10, 127, 5), createKey(5, 10, 128, 5), createKey(5, 10, 129, 5), createKey(5, 11, 126, 7), createKey(5, 11, 127, 7), createKey(5, 11, 128, 7), createKey(5, 11, 129, 7)));
List<Put> puts = new ArrayList<>();
for (byte[] key : keys) {
puts.add(new Put(key).addColumn(SharedTestEnvRule.COLUMN_FAMILY, Bytes.toBytes(0), Bytes.toBytes(0)));
}
table.put(puts);
// match keys with 5 in the first position and 126/127/128/129 in the 3rd position
FuzzyRowFilter filter = new FuzzyRowFilter(ImmutableList.of(Pair.newPair(createKey(5, 0, 126, 0), createFuzzyMask(0, 1, 0, 1)), Pair.newPair(createKey(5, 0, 127, 0), createFuzzyMask(0, 1, 0, 1)), Pair.newPair(createKey(5, 0, 128, 0), createFuzzyMask(0, 1, 0, 1)), Pair.newPair(createKey(5, 0, 129, 0), createFuzzyMask(0, 1, 0, 1))));
Scan scan = new Scan().setFilter(filter);
Set<String> expectedKeys = new HashSet<>(keys.size());
for (byte[] key : keys) {
expectedKeys.add(toFuzzyKeyString(key));
}
Set<String> actualKeys = new HashSet(keys.size());
// all 8 keys should be matched
try (ResultScanner scanner = table.getScanner(scan)) {
for (Result result : scanner) {
actualKeys.add(toFuzzyKeyString(CellUtil.cloneRow(result.rawCells()[0])));
}
}
// TODO: investigate why HBase has these empty rows.
actualKeys.remove("[]");
assertEquals(expectedKeys, actualKeys);
}
use of org.apache.hadoop.hbase.filter.FuzzyRowFilter in project java-bigtable-hbase by googleapis.
the class TestFuzzyRowFilterAdapter method fuzzyKeysAreTranslatedToRegularExpressions.
@Test
public void fuzzyKeysAreTranslatedToRegularExpressions() throws IOException {
List<Pair<byte[], byte[]>> testPairs = ImmutableList.<Pair<byte[], byte[]>>builder().add(new Pair<>(Bytes.toBytes("abcd"), new byte[] { -1, -1, -1, -1 })).add(new Pair<>(Bytes.toBytes(".fgh"), new byte[] { 0, 0, 1, 0 })).add(new Pair<>(Bytes.toBytes("ijkl"), new byte[] { 1, 1, 1, 1 })).build();
FuzzyRowFilter filter = new FuzzyRowFilter(testPairs);
Filters.Filter adaptedFilter = adapter.adapt(context, filter);
Filters.Filter expected = FILTERS.interleave().filter(FILTERS.key().regex("abcd\\C*")).filter(FILTERS.key().regex("\\.f\\Ch\\C*")).filter(FILTERS.key().regex("\\C\\C\\C\\C\\C*"));
Assert.assertEquals(expected.toProto(), adaptedFilter.toProto());
}
use of org.apache.hadoop.hbase.filter.FuzzyRowFilter in project kylin by apache.
the class CubeHBaseRPC method applyFuzzyFilter.
public static void applyFuzzyFilter(Scan scan, List<org.apache.kylin.common.util.Pair<byte[], byte[]>> fuzzyKeys) {
if (fuzzyKeys != null && fuzzyKeys.size() > 0) {
FuzzyRowFilter rowFilter = new FuzzyRowFilter(convertToHBasePair(fuzzyKeys));
Filter filter = scan.getFilter();
if (filter != null) {
// may have existed InclusiveStopFilter, see buildScan
FilterList filterList = new FilterList();
filterList.addFilter(filter);
filterList.addFilter(rowFilter);
scan.setFilter(filterList);
} else {
scan.setFilter(rowFilter);
}
}
}
use of org.apache.hadoop.hbase.filter.FuzzyRowFilter in project pinpoint by pinpoint-apm.
the class FuzzyRowFilterTest method test.
@Test
public void test() {
byte[] a1 = { '?', 5 };
byte[] a2 = { '?', 6 };
byte[] fuzzy = { 1, 0 };
Pair<byte[], byte[]> fuzzyPair1 = new Pair<>(a1, fuzzy);
Pair<byte[], byte[]> fuzzyPair2 = new Pair<>(a2, fuzzy);
FuzzyRowFilter filter = new FuzzyRowFilter(Arrays.asList(fuzzyPair1, fuzzyPair2));
KeyValue keyValue = new KeyValue(new byte[] { 0, 1 }, 1L);
Filter.ReturnCode returnCode = filter.filterKeyValue(keyValue);
Assert.assertEquals(returnCode, Filter.ReturnCode.SEEK_NEXT_USING_HINT);
KeyValue keyValue2 = new KeyValue(new byte[] { 0, 5 }, 1L);
Filter.ReturnCode returnCode2 = filter.filterKeyValue(keyValue2);
Assert.assertEquals(returnCode2, Filter.ReturnCode.INCLUDE);
}
use of org.apache.hadoop.hbase.filter.FuzzyRowFilter in project pinpoint by naver.
the class FuzzyRowFilterTest method test.
@Test
public void test() {
byte[] a1 = { '?', 5 };
byte[] a2 = { '?', 6 };
byte[] fuzzy = { 1, 0 };
Pair<byte[], byte[]> fuzzyPair1 = new Pair<>(a1, fuzzy);
Pair<byte[], byte[]> fuzzyPair2 = new Pair<>(a2, fuzzy);
FuzzyRowFilter filter = new FuzzyRowFilter(Arrays.asList(fuzzyPair1, fuzzyPair2));
KeyValue keyValue = new KeyValue(new byte[] { 0, 1 }, 1L);
Filter.ReturnCode returnCode = filter.filterKeyValue(keyValue);
Assert.assertEquals(returnCode, Filter.ReturnCode.SEEK_NEXT_USING_HINT);
KeyValue keyValue2 = new KeyValue(new byte[] { 0, 5 }, 1L);
Filter.ReturnCode returnCode2 = filter.filterKeyValue(keyValue2);
Assert.assertEquals(returnCode2, Filter.ReturnCode.INCLUDE);
}
Aggregations