Search in sources :

Example 56 with ExtractionDimensionSpec

use of io.druid.query.dimension.ExtractionDimensionSpec in project druid by druid-io.

the class TopNQueryRunnerTest method testTopNQueryCardinalityAggregatorWithExtractionFn.

@Test
public void testTopNQueryCardinalityAggregatorWithExtractionFn() {
    String helloJsFn = "function(str) { return 'hello' }";
    ExtractionFn helloFn = new JavaScriptExtractionFn(helloJsFn, false, JavaScriptConfig.getEnabledInstance());
    DimensionSpec dimSpec = new ExtractionDimensionSpec(QueryRunnerTestHelper.marketDimension, QueryRunnerTestHelper.marketDimension, helloFn);
    ImmutableList<DimensionSpec> aggregatorDimensionSpecs = ImmutableList.<DimensionSpec>of(new ExtractionDimensionSpec(QueryRunnerTestHelper.qualityDimension, QueryRunnerTestHelper.qualityDimension, helloFn));
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(dimSpec).metric(new NumericTopNMetricSpec("numVals")).threshold(10).intervals(QueryRunnerTestHelper.firstToThird).aggregators(duplicateAggregators(new CardinalityAggregatorFactory("numVals", aggregatorDimensionSpecs, false), new CardinalityAggregatorFactory("numVals1", aggregatorDimensionSpecs, false))).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(new DateTime("2011-04-01T00:00:00.000Z"), new TopNResultValue(withDuplicateResults(Collections.singletonList(ImmutableMap.<String, Object>of("market", "hello", "numVals", 1.0002442201269182d)), "numVals", "numVals1"))));
    assertExpectedResults(expectedResults, query);
}
Also used : ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) ListFilteredDimensionSpec(io.druid.query.dimension.ListFilteredDimensionSpec) DimensionSpec(io.druid.query.dimension.DimensionSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) LookupExtractionFn(io.druid.query.lookup.LookupExtractionFn) ExtractionFn(io.druid.query.extraction.ExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) DimExtractionFn(io.druid.query.extraction.DimExtractionFn) StrlenExtractionFn(io.druid.query.extraction.StrlenExtractionFn) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) TimeFormatExtractionFn(io.druid.query.extraction.TimeFormatExtractionFn) CardinalityAggregatorFactory(io.druid.query.aggregation.cardinality.CardinalityAggregatorFactory) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 57 with ExtractionDimensionSpec

use of io.druid.query.dimension.ExtractionDimensionSpec in project druid by druid-io.

the class TopNQueryRunnerTest method testTopNDimExtractionFastTopNOptimal.

@Test
public // Test a "direct" query
void testTopNDimExtractionFastTopNOptimal() {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.marketDimension, QueryRunnerTestHelper.marketDimension, new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("spot", "2spot0", "total_market", "1total_market0", "upfront", "3upfront0"), false), true, null, true, false))).metric("rows").threshold(4).intervals(QueryRunnerTestHelper.firstToThird).aggregators(QueryRunnerTestHelper.commonAggregators).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).build();
    List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<>(new DateTime("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "2spot0", "rows", 18L, "index", 2231.8768157958984D, "addRowsIndexConstant", 2250.8768157958984D, "uniques", QueryRunnerTestHelper.UNIQUES_9), ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "1total_market0", "rows", 4L, "index", 5351.814697265625D, "addRowsIndexConstant", 5356.814697265625D, "uniques", QueryRunnerTestHelper.UNIQUES_2), ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "3upfront0", "rows", 4L, "index", 4875.669677734375D, "addRowsIndexConstant", 4880.669677734375D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
    assertExpectedResults(expectedResults, query);
}
Also used : HyperUniqueFinalizingPostAggregator(io.druid.query.aggregation.hyperloglog.HyperUniqueFinalizingPostAggregator) PostAggregator(io.druid.query.aggregation.PostAggregator) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) LookupExtractionFn(io.druid.query.lookup.LookupExtractionFn) MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 58 with ExtractionDimensionSpec

use of io.druid.query.dimension.ExtractionDimensionSpec 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 59 with ExtractionDimensionSpec

use of io.druid.query.dimension.ExtractionDimensionSpec in project druid by druid-io.

the class ExpressionVirtualColumnTest method testDimensionSelectorWithExtraction.

@Test
public void testDimensionSelectorWithExtraction() {
    final DimensionSelector selector = XPLUSY.makeDimensionSelector(new ExtractionDimensionSpec("expr", "x", new BucketExtractionFn(1.0, 0.0)), COLUMN_SELECTOR_FACTORY);
    final ValueMatcher nullMatcher = selector.makeValueMatcher((String) null);
    final ValueMatcher fiveMatcher = selector.makeValueMatcher("5");
    final ValueMatcher nonNullMatcher = selector.makeValueMatcher(Predicates.<String>notNull());
    COLUMN_SELECTOR_FACTORY.setRow(ROW0);
    Assert.assertEquals(true, nullMatcher.matches());
    Assert.assertEquals(false, fiveMatcher.matches());
    Assert.assertEquals(false, nonNullMatcher.matches());
    Assert.assertEquals(null, selector.lookupName(selector.getRow().get(0)));
    COLUMN_SELECTOR_FACTORY.setRow(ROW1);
    Assert.assertEquals(true, nullMatcher.matches());
    Assert.assertEquals(false, fiveMatcher.matches());
    Assert.assertEquals(false, nonNullMatcher.matches());
    Assert.assertEquals(null, selector.lookupName(selector.getRow().get(0)));
    COLUMN_SELECTOR_FACTORY.setRow(ROW2);
    Assert.assertEquals(false, nullMatcher.matches());
    Assert.assertEquals(true, fiveMatcher.matches());
    Assert.assertEquals(true, nonNullMatcher.matches());
    Assert.assertEquals("5", selector.lookupName(selector.getRow().get(0)));
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) BucketExtractionFn(io.druid.query.extraction.BucketExtractionFn) ValueMatcher(io.druid.query.filter.ValueMatcher) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Aggregations

ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)59 Test (org.junit.Test)56 LookupExtractionFn (io.druid.query.lookup.LookupExtractionFn)36 Result (io.druid.query.Result)29 DateTime (org.joda.time.DateTime)29 RegexDimExtractionFn (io.druid.query.extraction.RegexDimExtractionFn)26 PostAggregator (io.druid.query.aggregation.PostAggregator)24 HyperUniqueFinalizingPostAggregator (io.druid.query.aggregation.hyperloglog.HyperUniqueFinalizingPostAggregator)24 TimeFormatExtractionFn (io.druid.query.extraction.TimeFormatExtractionFn)23 JavaScriptExtractionFn (io.druid.query.extraction.JavaScriptExtractionFn)19 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)18 ExtractionFn (io.druid.query.extraction.ExtractionFn)18 MapLookupExtractor (io.druid.query.extraction.MapLookupExtractor)18 Row (io.druid.data.input.Row)17 DimExtractionFn (io.druid.query.extraction.DimExtractionFn)17 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)16 StrlenExtractionFn (io.druid.query.extraction.StrlenExtractionFn)15 DimensionSpec (io.druid.query.dimension.DimensionSpec)13 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)10 RegexFilteredDimensionSpec (io.druid.query.dimension.RegexFilteredDimensionSpec)10