Search in sources :

Example 21 with ExtractionDimensionSpec

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

the class TopNQueryRunnerTest method testInvertedTopNLexicographicDimExtractionWithPreviousStop2.

@Test
public void testInvertedTopNLexicographicDimExtractionWithPreviousStop2() {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.marketDimension, QueryRunnerTestHelper.marketDimension, new RegexDimExtractionFn("..(.)", false, null))).metric(new InvertedTopNMetricSpec(new DimensionTopNMetricSpec("p", StringComparators.LEXICOGRAPHIC))).threshold(4).intervals(QueryRunnerTestHelper.firstToThird).aggregators(QueryRunnerTestHelper.commonAggregators).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).build();
    List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<TopNResultValue>(new DateTime("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "o", "rows", 18L, "index", 2231.8768157958984D, "addRowsIndexConstant", 2250.8768157958984D, "uniques", QueryRunnerTestHelper.UNIQUES_9), ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "f", "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) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 22 with ExtractionDimensionSpec

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

the class TopNQueryRunnerTest method testTopNTimeExtraction.

@Test
public void testTopNTimeExtraction() {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(new ExtractionDimensionSpec(Column.TIME_COLUMN_NAME, "dayOfWeek", new TimeFormatExtractionFn("EEEE", null, null, null, false))).metric("index").threshold(2).intervals(QueryRunnerTestHelper.fullOnInterval).aggregators(Arrays.asList(QueryRunnerTestHelper.rowsCount, QueryRunnerTestHelper.indexDoubleSum)).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).build();
    List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<>(new DateTime("2011-01-12T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>of("dayOfWeek", "Wednesday", "rows", 182L, "index", 76010.28100585938, "addRowsIndexConstant", 76193.28100585938), ImmutableMap.<String, Object>of("dayOfWeek", "Thursday", "rows", 182L, "index", 75203.26300811768, "addRowsIndexConstant", 75386.26300811768)))));
    assertExpectedResults(expectedResults, query);
}
Also used : TimeFormatExtractionFn(io.druid.query.extraction.TimeFormatExtractionFn) HyperUniqueFinalizingPostAggregator(io.druid.query.aggregation.hyperloglog.HyperUniqueFinalizingPostAggregator) PostAggregator(io.druid.query.aggregation.PostAggregator) DateTime(org.joda.time.DateTime) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Result(io.druid.query.Result) Test(org.junit.Test)

Example 23 with ExtractionDimensionSpec

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

the class TopNQueryRunnerTest method testTopNWithEmptyStringProducingDimExtractionFn.

@Test
public /**
   * This test exists only to show what the current behavior is and not necessarily to define that this is
   * correct behavior.  In fact, the behavior when returning the empty string from a DimExtractionFn is, by
   * contract, undefined, so this can do anything.
   */
void testTopNWithEmptyStringProducingDimExtractionFn() {
    final ExtractionFn emptyStringDimExtraction = new DimExtractionFn() {

        @Override
        public byte[] getCacheKey() {
            return new byte[] { (byte) 0xFF };
        }

        @Override
        public String apply(String dimValue) {
            return dimValue.equals("total_market") ? "" : dimValue;
        }

        @Override
        public boolean preservesOrdering() {
            return false;
        }

        @Override
        public ExtractionType getExtractionType() {
            return ExtractionType.MANY_TO_ONE;
        }
    };
    final TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).metric("rows").threshold(4).intervals(QueryRunnerTestHelper.firstToThird).aggregators(QueryRunnerTestHelper.commonAggregators).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.marketDimension, QueryRunnerTestHelper.marketDimension, emptyStringDimExtraction)).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, "spot", "rows", 18L, "index", 2231.8768157958984D, "addRowsIndexConstant", 2250.8768157958984D, "uniques", QueryRunnerTestHelper.UNIQUES_9), new LinkedHashMap<String, Object>() {

        {
            put(QueryRunnerTestHelper.marketDimension, "");
            put("rows", 4L);
            put("index", 5351.814697265625D);
            put("addRowsIndexConstant", 5356.814697265625D);
            put("uniques", QueryRunnerTestHelper.UNIQUES_2);
        }
    }, ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "upfront", "rows", 4L, "index", 4875.669677734375D, "addRowsIndexConstant", 4880.669677734375D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
    assertExpectedResults(expectedResults, query);
}
Also used : DateTime(org.joda.time.DateTime) LinkedHashMap(java.util.LinkedHashMap) 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) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) DimExtractionFn(io.druid.query.extraction.DimExtractionFn) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 24 with ExtractionDimensionSpec

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

the class TopNQueryRunnerTest method testTopNLexicographicDimExtractionWithPreviousStop.

@Test
public void testTopNLexicographicDimExtractionWithPreviousStop() {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.marketDimension, QueryRunnerTestHelper.marketDimension, new RegexDimExtractionFn("(.)", false, null))).metric(new DimensionTopNMetricSpec("s", StringComparators.LEXICOGRAPHIC)).threshold(4).intervals(QueryRunnerTestHelper.firstToThird).aggregators(QueryRunnerTestHelper.commonAggregators).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).build();
    List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<TopNResultValue>(new DateTime("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "t", "rows", 4L, "index", 5351.814697265625D, "addRowsIndexConstant", 5356.814697265625D, "uniques", QueryRunnerTestHelper.UNIQUES_2), ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "u", "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) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 25 with ExtractionDimensionSpec

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

the class CalciteQueryTest method testFilterAndGroupByLookup.

@Test
public void testFilterAndGroupByLookup() throws Exception {
    final RegisteredLookupExtractionFn extractionFn = new RegisteredLookupExtractionFn(null, "lookyloo", false, null, false, true);
    testQuery("SELECT LOOKUP(dim1, 'lookyloo'), COUNT(*) FROM foo\n" + "WHERE LOOKUP(dim1, 'lookyloo') <> 'xxx'\n" + "GROUP BY LOOKUP(dim1, 'lookyloo')", ImmutableList.<Query>of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(QSS(Filtration.eternity())).setGranularity(Granularities.ALL).setDimFilter(NOT(SELECTOR("dim1", "xxx", extractionFn))).setDimensions(DIMS(new ExtractionDimensionSpec("dim1", "d0", ValueType.STRING, extractionFn))).setAggregatorSpecs(AGGS(new CountAggregatorFactory("a0"))).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { "", 5L }, new Object[] { "xabc", 1L }));
}
Also used : CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) RegisteredLookupExtractionFn(io.druid.query.lookup.RegisteredLookupExtractionFn) 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