Search in sources :

Example 1 with FuzzyRowFilter

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);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) ArrayList(java.util.ArrayList) FuzzyRowFilter(org.apache.hadoop.hbase.filter.FuzzyRowFilter) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) Scan(org.apache.hadoop.hbase.client.Scan) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with FuzzyRowFilter

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());
}
Also used : Filters(com.google.cloud.bigtable.data.v2.models.Filters) FuzzyRowFilter(org.apache.hadoop.hbase.filter.FuzzyRowFilter) Pair(org.apache.hadoop.hbase.util.Pair) Test(org.junit.Test)

Example 3 with FuzzyRowFilter

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);
        }
    }
}
Also used : Filter(org.apache.hadoop.hbase.filter.Filter) FuzzyRowFilter(org.apache.hadoop.hbase.filter.FuzzyRowFilter) FilterList(org.apache.hadoop.hbase.filter.FilterList) FuzzyRowFilter(org.apache.hadoop.hbase.filter.FuzzyRowFilter)

Example 4 with FuzzyRowFilter

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);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) Filter(org.apache.hadoop.hbase.filter.Filter) FuzzyRowFilter(org.apache.hadoop.hbase.filter.FuzzyRowFilter) FuzzyRowFilter(org.apache.hadoop.hbase.filter.FuzzyRowFilter) Pair(org.apache.hadoop.hbase.util.Pair) Test(org.junit.Test)

Example 5 with FuzzyRowFilter

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);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) Filter(org.apache.hadoop.hbase.filter.Filter) FuzzyRowFilter(org.apache.hadoop.hbase.filter.FuzzyRowFilter) FuzzyRowFilter(org.apache.hadoop.hbase.filter.FuzzyRowFilter) Pair(org.apache.hadoop.hbase.util.Pair) Test(org.junit.Test)

Aggregations

FuzzyRowFilter (org.apache.hadoop.hbase.filter.FuzzyRowFilter)7 Test (org.junit.Test)6 Pair (org.apache.hadoop.hbase.util.Pair)4 ArrayList (java.util.ArrayList)3 Put (org.apache.hadoop.hbase.client.Put)3 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)3 Scan (org.apache.hadoop.hbase.client.Scan)3 Table (org.apache.hadoop.hbase.client.Table)3 Filter (org.apache.hadoop.hbase.filter.Filter)3 KeyValue (org.apache.hadoop.hbase.KeyValue)2 Filters (com.google.cloud.bigtable.data.v2.models.Filters)1 HashSet (java.util.HashSet)1 Result (org.apache.hadoop.hbase.client.Result)1 FilterList (org.apache.hadoop.hbase.filter.FilterList)1