use of org.apache.druid.query.filter.BloomKFilter in project druid by druid-io.
the class BloomFilterGroupByQueryTest method testQuery.
@Test
public void testQuery() throws Exception {
String query = "{" + "\"queryType\": \"groupBy\"," + "\"dataSource\": \"test_datasource\"," + "\"granularity\": \"ALL\"," + "\"dimensions\": []," + "\"filter\":{ \"type\":\"selector\", \"dimension\":\"market\", \"value\":\"upfront\"}," + "\"aggregations\": [" + " { \"type\": \"bloom\", \"name\": \"blooming_quality\", \"field\": \"quality\" }" + "]," + "\"intervals\": [ \"1970/2050\" ]" + "}";
MapBasedRow row = ingestAndQuery(query);
BloomKFilter filter = BloomKFilter.deserialize((ByteBuffer) row.getRaw("blooming_quality"));
Assert.assertTrue(filter.testString("mezzanine"));
Assert.assertTrue(filter.testString("premium"));
Assert.assertFalse(filter.testString("entertainment"));
}
use of org.apache.druid.query.filter.BloomKFilter in project druid by druid-io.
the class BloomFilterGroupByQueryTest method testNestedQueryComplex.
@Test
public void testNestedQueryComplex() throws Exception {
if (!isV2) {
return;
}
String query = "{" + "\"queryType\": \"groupBy\"," + "\"dataSource\": {" + "\"type\": \"query\"," + "\"query\": {" + "\"queryType\":\"groupBy\"," + "\"dataSource\": \"test_datasource\"," + "\"intervals\": [ \"1970/2050\" ]," + "\"granularity\":\"ALL\"," + "\"dimensions\":[]," + "\"filter\":{ \"type\":\"selector\", \"dimension\":\"market\", \"value\":\"upfront\"}," + "\"aggregations\": [{ \"type\":\"bloom\", \"name\":\"innerBloom\", \"field\":\"quality\"}]" + "}" + "}," + "\"granularity\": \"ALL\"," + "\"dimensions\": []," + "\"aggregations\": [" + " { \"type\": \"bloom\", \"name\": \"innerBloom\", \"field\": \"innerBloom\" }" + "]," + "\"intervals\": [ \"1970/2050\" ]" + "}";
MapBasedRow row = ingestAndQuery(query);
BloomKFilter filter = BloomKFilter.deserialize((ByteBuffer) row.getRaw("innerBloom"));
Assert.assertTrue(filter.testString("mezzanine"));
Assert.assertTrue(filter.testString("premium"));
Assert.assertFalse(filter.testString("entertainment"));
}
use of org.apache.druid.query.filter.BloomKFilter in project druid by druid-io.
the class BloomFilterExpressionsTest method testAddLong.
@Test
public void testAddLong() {
Expr expr = Parser.parse("bloom_filter_add(1234, bloomy)", macroTable);
ExprEval eval = expr.eval(inputBindings);
Assert.assertEquals(BloomFilterExpressions.BLOOM_FILTER_TYPE, eval.type());
Assert.assertTrue(eval.value() instanceof BloomKFilter);
Assert.assertTrue(((BloomKFilter) eval.value()).testLong(SOME_LONG));
expr = Parser.parse("bloom_filter_add(long, bloomy)", macroTable);
eval = expr.eval(inputBindings);
Assert.assertEquals(BloomFilterExpressions.BLOOM_FILTER_TYPE, eval.type());
Assert.assertTrue(eval.value() instanceof BloomKFilter);
Assert.assertTrue(((BloomKFilter) eval.value()).testLong(SOME_LONG));
}
use of org.apache.druid.query.filter.BloomKFilter in project druid by druid-io.
the class BloomFilterExpressionsTest method testCreate.
@Test
public void testCreate() {
Expr expr = Parser.parse("bloom_filter(100)", macroTable);
ExprEval eval = expr.eval(inputBindings);
Assert.assertEquals(BloomFilterExpressions.BLOOM_FILTER_TYPE, eval.type());
Assert.assertTrue(eval.value() instanceof BloomKFilter);
Assert.assertEquals(1024, ((BloomKFilter) eval.value()).getBitSize());
}
use of org.apache.druid.query.filter.BloomKFilter in project druid by druid-io.
the class BaseBloomFilterAggregator method init.
@Override
public void init(ByteBuffer buf, int position) {
final ByteBuffer mutationBuffer = buf.duplicate();
mutationBuffer.position(position);
BloomKFilter filter = new BloomKFilter(maxNumEntries);
BloomKFilter.serialize(mutationBuffer, filter);
}
Aggregations