Search in sources :

Example 6 with CardinalityAggregatorFactory

use of io.druid.query.aggregation.cardinality.CardinalityAggregatorFactory in project druid by druid-io.

the class CalciteQueryTest method testCountDistinctOfLookup.

@Test
public void testCountDistinctOfLookup() throws Exception {
    final RegisteredLookupExtractionFn extractionFn = new RegisteredLookupExtractionFn(null, "lookyloo", false, null, false, true);
    testQuery("SELECT COUNT(DISTINCT LOOKUP(dim1, 'lookyloo')) FROM foo", ImmutableList.<Query>of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(QSS(Filtration.eternity())).granularity(Granularities.ALL).aggregators(AGGS(new CardinalityAggregatorFactory("a0", ImmutableList.<DimensionSpec>of(new ExtractionDimensionSpec("dim1", null, extractionFn)), false))).context(TIMESERIES_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 2L }));
}
Also used : RegisteredLookupExtractionFn(io.druid.query.lookup.RegisteredLookupExtractionFn) CardinalityAggregatorFactory(io.druid.query.aggregation.cardinality.CardinalityAggregatorFactory) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 7 with CardinalityAggregatorFactory

use of io.druid.query.aggregation.cardinality.CardinalityAggregatorFactory in project druid by druid-io.

the class GroupByQueryRunnerTest method testGroupByCardinalityAggOnFloat.

@Test
public void testGroupByCardinalityAggOnFloat() {
    GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird).setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("market", "alias"))).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.rowsCount, new CardinalityAggregatorFactory("numVals", ImmutableList.<DimensionSpec>of(new DefaultDimensionSpec(QueryRunnerTestHelper.indexMetric, QueryRunnerTestHelper.indexMetric)), false))).setGranularity(QueryRunnerTestHelper.dayGran).build();
    List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "spot", "rows", 9L, "numVals", 9.019833517963864d), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "total_market", "rows", 2L, "numVals", 2.000977198748901d), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "upfront", "rows", 2L, "numVals", 2.000977198748901d), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "spot", "rows", 9L, "numVals", 9.019833517963864d), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "total_market", "rows", 2L, "numVals", 2.000977198748901d), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "upfront", "rows", 2L, "numVals", 2.000977198748901d));
    Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
    TestHelper.assertExpectedObjects(expectedResults, results, "");
}
Also used : DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) ListFilteredDimensionSpec(io.druid.query.dimension.ListFilteredDimensionSpec) DimensionSpec(io.druid.query.dimension.DimensionSpec) Row(io.druid.data.input.Row) CardinalityAggregatorFactory(io.druid.query.aggregation.cardinality.CardinalityAggregatorFactory) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Aggregations

CardinalityAggregatorFactory (io.druid.query.aggregation.cardinality.CardinalityAggregatorFactory)7 DimensionSpec (io.druid.query.dimension.DimensionSpec)6 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)6 Test (org.junit.Test)6 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)5 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)5 Row (io.druid.data.input.Row)3 RegexFilteredDimensionSpec (io.druid.query.dimension.RegexFilteredDimensionSpec)3 Result (io.druid.query.Result)2 DimExtractionFn (io.druid.query.extraction.DimExtractionFn)2 ExtractionFn (io.druid.query.extraction.ExtractionFn)2 JavaScriptExtractionFn (io.druid.query.extraction.JavaScriptExtractionFn)2 RegexDimExtractionFn (io.druid.query.extraction.RegexDimExtractionFn)2 StrlenExtractionFn (io.druid.query.extraction.StrlenExtractionFn)2 TimeFormatExtractionFn (io.druid.query.extraction.TimeFormatExtractionFn)2 LookupExtractionFn (io.druid.query.lookup.LookupExtractionFn)2 DateTime (org.joda.time.DateTime)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ISE (io.druid.java.util.common.ISE)1 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)1