Example usage for org.apache.hadoop.util.bloom Filter membershipTest

List of usage examples for org.apache.hadoop.util.bloom Filter membershipTest

Introduction

In this page you can find the example usage for org.apache.hadoop.util.bloom Filter membershipTest.

Prototype

public abstract boolean membershipTest(Key key);

Source Link

Document

Determines wether a specified key belongs to this filter.

Usage

From source file:brickhouse.udf.bloom.BloomContainsUDF.java

License:Apache License

public Boolean evaluate(String key, String bloomFilter) throws HiveException {
    Filter bloom = BloomFactory.GetBloomFilter(bloomFilter);
    if (bloom != null) {
        return bloom.membershipTest(new Key(key.getBytes()));
    } else {//ww w  . j  a  v a 2  s  . c  om
        throw new HiveException("Unable to find bloom " + bloomFilter);
    }
}

From source file:hivemall.sketch.bloom.BloomAndUDFTest.java

License:Apache License

private static void assertNotContains(@Nonnull Filter expected, @Nonnull Filter actual, long seed, int size) {
    final Key key = new Key();

    final Random rnd1 = new Random(seed);
    for (int i = 0; i < size; i++) {
        double d = rnd1.nextGaussian();
        String s = Double.toHexString(d);
        key.set(s.getBytes(), 1.0);//from  w  w  w.  jav  a2s.c  o m
        Assert.assertEquals(expected.membershipTest(key), actual.membershipTest(key));
    }
}

From source file:hivemall.sketch.bloom.BloomContainsUDF.java

License:Apache License

@Nullable
public Boolean evaluate(@Nullable Text bloomStr, @Nullable Text keyStr) throws HiveException {
    if (bloomStr == null || key == null) {
        return null;
    }/*from  w  w  w  .j  av  a 2  s  . co m*/

    final Filter bloom;
    if (prevFilter != null && prevKey.equals(keyStr)) {
        bloom = prevFilter;
    } else {
        try {
            bloom = BloomFilterUtils.deserialize(bloomStr, new DynamicBloomFilter());
        } catch (IOException e) {
            throw new HiveException(e);
        }
        this.prevKey = keyStr;
        this.prevFilter = bloom;
        key.set(keyStr.getBytes(), 1.0d);
    }

    return Boolean.valueOf(bloom.membershipTest(key));
}

From source file:hivemall.sketch.bloom.BloomOrUDFTest.java

License:Apache License

private static void assertEquals(@Nonnull Filter expected, @Nonnull Filter actual, long seed, int size) {
    final Key key = new Key();

    final Random rnd1 = new Random(seed);
    for (int i = 0; i < size; i++) {
        double d = rnd1.nextGaussian();
        String s = Double.toHexString(d);
        key.set(s.getBytes(), 1.0);/*from  w  w  w. ja  va 2s  . c  om*/
        Assert.assertEquals(expected.membershipTest(key), actual.membershipTest(key));
    }
}

From source file:org.apache.mahout.utils.nlp.collocations.llr.BloomTokenFilterTest.java

License:Apache License

/** test standalone filter without tokenfilter wrapping */
@Test// www .  j a v  a 2 s. co  m
public void testFilter() throws IOException {
    Filter filter = getFilter(filterTokens);
    Key k = new Key();
    for (String s : filterTokens) {
        setKey(k, s);
        assertTrue("Key for string " + s + " should be filter member", filter.membershipTest(k));
    }

    for (String s : notFilterTokens) {
        setKey(k, s);
        assertFalse("Key for string " + s + " should not be filter member", filter.membershipTest(k));
    }
}