Search in sources :

Example 1 with BloomFilterAggregatorFactory

use of org.apache.druid.query.aggregation.bloom.BloomFilterAggregatorFactory in project druid by druid-io.

the class BloomFilterSqlAggregatorTest method testBloomFilterAgg.

@Test
public void testBloomFilterAgg() throws Exception {
    cannotVectorize();
    BloomKFilter expected1 = new BloomKFilter(TEST_NUM_ENTRIES);
    for (InputRow row : CalciteTests.ROWS1_WITH_NUMERIC_DIMS) {
        String raw = NullHandling.emptyToNullIfNeeded((String) row.getRaw("dim1"));
        if (raw == null) {
            expected1.addBytes(null, 0, 0);
        } else {
            expected1.addString(raw);
        }
    }
    testQuery("SELECT\n" + "BLOOM_FILTER(dim1, 1000)\n" + "FROM numfoo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).aggregators(ImmutableList.of(new BloomFilterAggregatorFactory("a0:agg", new DefaultDimensionSpec("dim1", "a0:dim1"), TEST_NUM_ENTRIES))).context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { CalciteTests.getJsonMapper().writeValueAsString(expected1) }));
}
Also used : InputRow(org.apache.druid.data.input.InputRow) BloomFilterAggregatorFactory(org.apache.druid.query.aggregation.bloom.BloomFilterAggregatorFactory) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 2 with BloomFilterAggregatorFactory

use of org.apache.druid.query.aggregation.bloom.BloomFilterAggregatorFactory in project druid by druid-io.

the class BloomFilterSqlAggregatorTest method testBloomFilterAggLongVirtualColumn.

@Test
public void testBloomFilterAggLongVirtualColumn() throws Exception {
    cannotVectorize();
    BloomKFilter expected1 = new BloomKFilter(TEST_NUM_ENTRIES);
    for (InputRow row : CalciteTests.ROWS1_WITH_NUMERIC_DIMS) {
        Object raw = row.getRaw("l1");
        if (raw == null) {
            if (NullHandling.replaceWithDefault()) {
                expected1.addLong(NullHandling.defaultLongValue());
            } else {
                expected1.addBytes(null, 0, 0);
            }
        } else {
            expected1.addLong(2 * ((Number) raw).longValue());
        }
    }
    testQuery("SELECT\n" + "BLOOM_FILTER(l1 * 2, 1000)\n" + "FROM numfoo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).virtualColumns(new ExpressionVirtualColumn("v0", "(\"l1\" * 2)", ColumnType.LONG, TestExprMacroTable.INSTANCE)).aggregators(ImmutableList.of(new BloomFilterAggregatorFactory("a0:agg", new DefaultDimensionSpec("v0", "a0:v0"), TEST_NUM_ENTRIES))).context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { CalciteTests.getJsonMapper().writeValueAsString(expected1) }));
}
Also used : ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) InputRow(org.apache.druid.data.input.InputRow) BloomFilterAggregatorFactory(org.apache.druid.query.aggregation.bloom.BloomFilterAggregatorFactory) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 3 with BloomFilterAggregatorFactory

use of org.apache.druid.query.aggregation.bloom.BloomFilterAggregatorFactory in project druid by druid-io.

the class BloomFilterSqlAggregatorTest method testBloomFilterAggLong.

@Test
public void testBloomFilterAggLong() throws Exception {
    cannotVectorize();
    BloomKFilter expected3 = new BloomKFilter(TEST_NUM_ENTRIES);
    for (InputRow row : CalciteTests.ROWS1_WITH_NUMERIC_DIMS) {
        Object raw = row.getRaw("l1");
        if (raw == null) {
            if (NullHandling.replaceWithDefault()) {
                expected3.addLong(NullHandling.defaultLongValue());
            } else {
                expected3.addBytes(null, 0, 0);
            }
        } else {
            expected3.addLong(((Number) raw).longValue());
        }
    }
    testQuery("SELECT\n" + "BLOOM_FILTER(l1, 1000)\n" + "FROM numfoo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).aggregators(ImmutableList.of(new BloomFilterAggregatorFactory("a0:agg", new DefaultDimensionSpec("l1", "a0:l1", ColumnType.LONG), TEST_NUM_ENTRIES))).context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { CalciteTests.getJsonMapper().writeValueAsString(expected3) }));
}
Also used : InputRow(org.apache.druid.data.input.InputRow) BloomFilterAggregatorFactory(org.apache.druid.query.aggregation.bloom.BloomFilterAggregatorFactory) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 4 with BloomFilterAggregatorFactory

use of org.apache.druid.query.aggregation.bloom.BloomFilterAggregatorFactory in project druid by druid-io.

the class BloomFilterSqlAggregatorTest method testBloomFilterAggDoubleVirtualColumn.

@Test
public void testBloomFilterAggDoubleVirtualColumn() throws Exception {
    cannotVectorize();
    BloomKFilter expected1 = new BloomKFilter(TEST_NUM_ENTRIES);
    for (InputRow row : CalciteTests.ROWS1_WITH_NUMERIC_DIMS) {
        Object raw = row.getRaw("d1");
        if (raw == null) {
            if (NullHandling.replaceWithDefault()) {
                expected1.addDouble(NullHandling.defaultDoubleValue());
            } else {
                expected1.addBytes(null, 0, 0);
            }
        } else {
            expected1.addDouble(2 * ((Number) raw).doubleValue());
        }
    }
    testQuery("SELECT\n" + "BLOOM_FILTER(d1 * 2, 1000)\n" + "FROM numfoo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).virtualColumns(new ExpressionVirtualColumn("v0", "(\"d1\" * 2)", ColumnType.DOUBLE, TestExprMacroTable.INSTANCE)).aggregators(ImmutableList.of(new BloomFilterAggregatorFactory("a0:agg", new DefaultDimensionSpec("v0", "a0:v0"), TEST_NUM_ENTRIES))).context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { CalciteTests.getJsonMapper().writeValueAsString(expected1) }));
}
Also used : ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) InputRow(org.apache.druid.data.input.InputRow) BloomFilterAggregatorFactory(org.apache.druid.query.aggregation.bloom.BloomFilterAggregatorFactory) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 5 with BloomFilterAggregatorFactory

use of org.apache.druid.query.aggregation.bloom.BloomFilterAggregatorFactory in project druid by druid-io.

the class BloomFilterSqlAggregatorTest method testBloomFilterTwoAggs.

@Test
public void testBloomFilterTwoAggs() throws Exception {
    cannotVectorize();
    BloomKFilter expected1 = new BloomKFilter(TEST_NUM_ENTRIES);
    BloomKFilter expected2 = new BloomKFilter(TEST_NUM_ENTRIES);
    for (InputRow row : CalciteTests.ROWS1_WITH_NUMERIC_DIMS) {
        String raw = NullHandling.emptyToNullIfNeeded((String) row.getRaw("dim1"));
        if (raw == null) {
            expected1.addBytes(null, 0, 0);
        } else {
            expected1.addString(raw);
        }
        List<String> lst = row.getDimension("dim2");
        if (lst.size() == 0) {
            expected2.addBytes(null, 0, 0);
        }
        for (String s : lst) {
            String val = NullHandling.emptyToNullIfNeeded(s);
            if (val == null) {
                expected2.addBytes(null, 0, 0);
            } else {
                expected2.addString(val);
            }
        }
    }
    testQuery("SELECT\n" + "BLOOM_FILTER(dim1, 1000),\n" + "BLOOM_FILTER(dim2, 1000)\n" + "FROM numfoo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).aggregators(ImmutableList.of(new BloomFilterAggregatorFactory("a0:agg", new DefaultDimensionSpec("dim1", "a0:dim1"), TEST_NUM_ENTRIES), new BloomFilterAggregatorFactory("a1:agg", new DefaultDimensionSpec("dim2", "a1:dim2"), TEST_NUM_ENTRIES))).context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { CalciteTests.getJsonMapper().writeValueAsString(expected1), CalciteTests.getJsonMapper().writeValueAsString(expected2) }));
}
Also used : InputRow(org.apache.druid.data.input.InputRow) BloomFilterAggregatorFactory(org.apache.druid.query.aggregation.bloom.BloomFilterAggregatorFactory) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Aggregations

BloomFilterAggregatorFactory (org.apache.druid.query.aggregation.bloom.BloomFilterAggregatorFactory)10 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)9 BloomKFilter (org.apache.druid.query.filter.BloomKFilter)9 BaseCalciteQueryTest (org.apache.druid.sql.calcite.BaseCalciteQueryTest)9 Test (org.junit.Test)9 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)8 InputRow (org.apache.druid.data.input.InputRow)7 ExpressionVirtualColumn (org.apache.druid.segment.virtual.ExpressionVirtualColumn)3 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)2 Nullable (javax.annotation.Nullable)1 RexNode (org.apache.calcite.rex.RexNode)1 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)1 FilteredAggregatorFactory (org.apache.druid.query.aggregation.FilteredAggregatorFactory)1 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)1 SubstringDimExtractionFn (org.apache.druid.query.extraction.SubstringDimExtractionFn)1 ColumnType (org.apache.druid.segment.column.ColumnType)1 Aggregation (org.apache.druid.sql.calcite.aggregation.Aggregation)1 DruidExpression (org.apache.druid.sql.calcite.expression.DruidExpression)1