Search in sources :

Example 1 with BloomDimFilter

use of org.apache.druid.query.filter.BloomDimFilter in project druid by druid-io.

the class BloomDimFilterSqlTest method testBloomFilterBigParameter.

@Ignore("this test is for comparison with testBloomFilterBigNoParam")
@Test
public void testBloomFilterBigParameter() throws Exception {
    BloomKFilter filter = new BloomKFilter(5_000_000);
    filter.addString("def");
    byte[] bytes = BloomFilterSerializersModule.bloomKFilterToBytes(filter);
    String base64 = StringUtils.encodeBase64String(bytes);
    testQuery("SELECT COUNT(*) FROM druid.foo WHERE bloom_filter_test(dim1, ?)", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).filters(new BloomDimFilter("dim1", BloomKFilterHolder.fromBloomKFilter(filter), null)).aggregators(aggregators(new CountAggregatorFactory("a0"))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 1L }), ImmutableList.of(new SqlParameter(SqlType.VARCHAR, base64)));
}
Also used : SqlParameter(org.apache.druid.sql.http.SqlParameter) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) BloomDimFilter(org.apache.druid.query.filter.BloomDimFilter) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) Ignore(org.junit.Ignore) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 2 with BloomDimFilter

use of org.apache.druid.query.filter.BloomDimFilter in project druid by druid-io.

the class BloomDimFilterSqlTest method testBloomFilter.

@Test
public void testBloomFilter() throws Exception {
    BloomKFilter filter = new BloomKFilter(1500);
    filter.addString("def");
    byte[] bytes = BloomFilterSerializersModule.bloomKFilterToBytes(filter);
    String base64 = StringUtils.encodeBase64String(bytes);
    testQuery(StringUtils.format("SELECT COUNT(*) FROM druid.foo WHERE bloom_filter_test(dim1, '%s')", base64), ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).filters(new BloomDimFilter("dim1", BloomKFilterHolder.fromBloomKFilter(filter), null)).aggregators(aggregators(new CountAggregatorFactory("a0"))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 1L }));
}
Also used : CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) BloomDimFilter(org.apache.druid.query.filter.BloomDimFilter) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 3 with BloomDimFilter

use of org.apache.druid.query.filter.BloomDimFilter in project druid by druid-io.

the class BloomDimFilterSqlTest method testBloomFilterVirtualColumnNumber.

@Test
public void testBloomFilterVirtualColumnNumber() throws Exception {
    BloomKFilter filter = new BloomKFilter(1500);
    filter.addFloat(20.2f);
    byte[] bytes = BloomFilterSerializersModule.bloomKFilterToBytes(filter);
    String base64 = StringUtils.encodeBase64String(bytes);
    testQuery(StringUtils.format("SELECT COUNT(*) FROM druid.foo WHERE bloom_filter_test(2 * CAST(dim1 AS float), '%s')", base64), ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).virtualColumns(expressionVirtualColumn("v0", "(2 * CAST(\"dim1\", 'DOUBLE'))", ColumnType.FLOAT)).filters(new BloomDimFilter("v0", BloomKFilterHolder.fromBloomKFilter(filter), null)).aggregators(aggregators(new CountAggregatorFactory("a0"))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 1L }));
}
Also used : CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) BloomDimFilter(org.apache.druid.query.filter.BloomDimFilter) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 4 with BloomDimFilter

use of org.apache.druid.query.filter.BloomDimFilter in project druid by druid-io.

the class BloomDimFilterSqlTest method testBloomFilters.

@Test
public void testBloomFilters() throws Exception {
    BloomKFilter filter = new BloomKFilter(1500);
    filter.addString("def");
    BloomKFilter filter2 = new BloomKFilter(1500);
    filter.addString("abc");
    byte[] bytes = BloomFilterSerializersModule.bloomKFilterToBytes(filter);
    byte[] bytes2 = BloomFilterSerializersModule.bloomKFilterToBytes(filter2);
    String base64 = StringUtils.encodeBase64String(bytes);
    String base642 = StringUtils.encodeBase64String(bytes2);
    testQuery(StringUtils.format("SELECT COUNT(*) FROM druid.foo WHERE bloom_filter_test(dim1, '%s') OR bloom_filter_test(dim2, '%s')", base64, base642), ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).filters(new OrDimFilter(new BloomDimFilter("dim1", BloomKFilterHolder.fromBloomKFilter(filter), null), new BloomDimFilter("dim2", BloomKFilterHolder.fromBloomKFilter(filter2), null))).aggregators(aggregators(new CountAggregatorFactory("a0"))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 2L }));
}
Also used : CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) OrDimFilter(org.apache.druid.query.filter.OrDimFilter) BloomDimFilter(org.apache.druid.query.filter.BloomDimFilter) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 5 with BloomDimFilter

use of org.apache.druid.query.filter.BloomDimFilter in project druid by druid-io.

the class BloomDimFilterSqlTest method testBloomFilterBigNoParam.

@Ignore("this test is really slow and is intended to use for comparisons with testBloomFilterBigParameter")
@Test
public void testBloomFilterBigNoParam() throws Exception {
    BloomKFilter filter = new BloomKFilter(5_000_000);
    filter.addString("def");
    byte[] bytes = BloomFilterSerializersModule.bloomKFilterToBytes(filter);
    String base64 = StringUtils.encodeBase64String(bytes);
    testQuery(StringUtils.format("SELECT COUNT(*) FROM druid.foo WHERE bloom_filter_test(dim1, '%s')", base64), ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).filters(new BloomDimFilter("dim1", BloomKFilterHolder.fromBloomKFilter(filter), null)).aggregators(aggregators(new CountAggregatorFactory("a0"))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 1L }));
}
Also used : CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) BloomDimFilter(org.apache.druid.query.filter.BloomDimFilter) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) Ignore(org.junit.Ignore) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Aggregations

BloomDimFilter (org.apache.druid.query.filter.BloomDimFilter)8 BloomKFilter (org.apache.druid.query.filter.BloomKFilter)8 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)6 BaseCalciteQueryTest (org.apache.druid.sql.calcite.BaseCalciteQueryTest)6 Test (org.junit.Test)6 IOException (java.io.IOException)2 Nullable (javax.annotation.Nullable)2 OrDimFilter (org.apache.druid.query.filter.OrDimFilter)2 Ignore (org.junit.Ignore)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 RexCall (org.apache.calcite.rex.RexCall)1 RexNode (org.apache.calcite.rex.RexNode)1 AndDimFilter (org.apache.druid.query.filter.AndDimFilter)1 BloomKFilterHolder (org.apache.druid.query.filter.BloomKFilterHolder)1 BoundDimFilter (org.apache.druid.query.filter.BoundDimFilter)1 DimFilter (org.apache.druid.query.filter.DimFilter)1 StringComparator (org.apache.druid.query.ordering.StringComparator)1 DruidExpression (org.apache.druid.sql.calcite.expression.DruidExpression)1