Search in sources :

Example 1 with BloomKFilter

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"));
}
Also used : MapBasedRow(org.apache.druid.data.input.MapBasedRow) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) GroupByQueryRunnerTest(org.apache.druid.query.groupby.GroupByQueryRunnerTest) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 2 with BloomKFilter

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"));
}
Also used : MapBasedRow(org.apache.druid.data.input.MapBasedRow) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) GroupByQueryRunnerTest(org.apache.druid.query.groupby.GroupByQueryRunnerTest) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 3 with BloomKFilter

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));
}
Also used : ExprEval(org.apache.druid.math.expr.ExprEval) Expr(org.apache.druid.math.expr.Expr) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 4 with BloomKFilter

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());
}
Also used : ExprEval(org.apache.druid.math.expr.ExprEval) Expr(org.apache.druid.math.expr.Expr) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 5 with BloomKFilter

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);
}
Also used : ByteBuffer(java.nio.ByteBuffer) BloomKFilter(org.apache.druid.query.filter.BloomKFilter)

Aggregations

BloomKFilter (org.apache.druid.query.filter.BloomKFilter)40 Test (org.junit.Test)37 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)20 BaseCalciteQueryTest (org.apache.druid.sql.calcite.BaseCalciteQueryTest)17 CardinalityAggregatorTest (org.apache.druid.query.aggregation.cardinality.CardinalityAggregatorTest)12 BloomFilterAggregatorFactory (org.apache.druid.query.aggregation.bloom.BloomFilterAggregatorFactory)9 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)8 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)8 BloomDimFilter (org.apache.druid.query.filter.BloomDimFilter)8 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)8 ByteBuffer (java.nio.ByteBuffer)7 InputRow (org.apache.druid.data.input.InputRow)7 MapBasedRow (org.apache.druid.data.input.MapBasedRow)4 Expr (org.apache.druid.math.expr.Expr)4 ExprEval (org.apache.druid.math.expr.ExprEval)4 GroupByQueryRunnerTest (org.apache.druid.query.groupby.GroupByQueryRunnerTest)4 DimensionSelector (org.apache.druid.segment.DimensionSelector)3 ExpressionVirtualColumn (org.apache.druid.segment.virtual.ExpressionVirtualColumn)3 IOException (java.io.IOException)2 Nullable (javax.annotation.Nullable)2