Search in sources :

Example 66 with ExtractionDimensionSpec

use of org.apache.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.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new ExtractionDimensionSpec(ColumnHolder.TIME_COLUMN_NAME, "dayOfWeek", new TimeFormatExtractionFn("EEEE", null, null, null, false))).metric("index").threshold(2).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).aggregators(QueryRunnerTestHelper.ROWS_COUNT, QueryRunnerTestHelper.INDEX_DOUBLE_SUM).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.of("dayOfWeek", "Wednesday", "rows", 182L, "index", 76010.28100585938, "addRowsIndexConstant", 76193.28100585938), ImmutableMap.of("dayOfWeek", "Thursday", "rows", 182L, "index", 75203.26300811768, "addRowsIndexConstant", 75386.26300811768)))));
    assertExpectedResults(expectedResults, query);
}
Also used : TimeFormatExtractionFn(org.apache.druid.query.extraction.TimeFormatExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 67 with ExtractionDimensionSpec

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

the class TopNQueryRunnerTest method testTopNDimExtractionFastTopNUnOptimalWithReplaceMissing.

@Test
public void testTopNDimExtractionFastTopNUnOptimalWithReplaceMissing() {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, QueryRunnerTestHelper.MARKET_DIMENSION, new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("spot", "2spot0", "total_market", "1total_market0", "upfront", "3upfront0"), false), false, "MISSING", false, false))).metric("rows").threshold(4).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).aggregators(commonAggregators).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "2spot0", "rows", 18L, "index", 2231.876812D, "addRowsIndexConstant", 2250.876812D, "uniques", QueryRunnerTestHelper.UNIQUES_9), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "1total_market0", "rows", 4L, "index", 5351.814783D, "addRowsIndexConstant", 5356.814783D, "uniques", QueryRunnerTestHelper.UNIQUES_2), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "3upfront0", "rows", 4L, "index", 4875.669692D, "addRowsIndexConstant", 4880.669692D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
    assertExpectedResults(expectedResults, query);
}
Also used : LookupExtractionFn(org.apache.druid.query.lookup.LookupExtractionFn) MapLookupExtractor(org.apache.druid.query.extraction.MapLookupExtractor) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 68 with ExtractionDimensionSpec

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

the class TopNQueryRunnerTest method testTopNDimExtractionNoAggregators.

@Test
public void testTopNDimExtractionNoAggregators() {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, QueryRunnerTestHelper.MARKET_DIMENSION, new RegexDimExtractionFn("(.)", false, null))).metric(new LexicographicTopNMetricSpec(QueryRunnerTestHelper.MARKET_DIMENSION)).threshold(4).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "s"), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "t"), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "u")))));
    assertExpectedResults(expectedResults, query);
}
Also used : RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 69 with ExtractionDimensionSpec

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

the class TopNQueryRunnerTest method testInvertedTopNLexicographicDimExtractionWithPreviousStop.

@Test
public void testInvertedTopNLexicographicDimExtractionWithPreviousStop() {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, QueryRunnerTestHelper.MARKET_DIMENSION, new RegexDimExtractionFn("(.)", false, null))).metric(new InvertedTopNMetricSpec(new DimensionTopNMetricSpec("u", StringComparators.LEXICOGRAPHIC))).threshold(4).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).aggregators(commonAggregators).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "t", "rows", 4L, "index", 5351.814783D, "addRowsIndexConstant", 5356.814783D, "uniques", QueryRunnerTestHelper.UNIQUES_2), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "s", "rows", 18L, "index", 2231.876812D, "addRowsIndexConstant", 2250.876812D, "uniques", QueryRunnerTestHelper.UNIQUES_9)))));
    assertExpectedResults(expectedResults, query);
}
Also used : RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 70 with ExtractionDimensionSpec

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

the class SearchQueryRunnerTest method testSearchOnTime.

@Test
public void testSearchOnTime() {
    SearchQuery searchQuery = Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).query("Friday").dimensions(new ExtractionDimensionSpec(ColumnHolder.TIME_COLUMN_NAME, "__time2", new TimeFormatExtractionFn("EEEE", null, null, null, false))).build();
    List<SearchHit> expectedHits = new ArrayList<>();
    expectedHits.add(new SearchHit("__time2", "Friday", 169));
    checkSearchQuery(searchQuery, expectedHits);
}
Also used : TimeFormatExtractionFn(org.apache.druid.query.extraction.TimeFormatExtractionFn) ArrayList(java.util.ArrayList) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)87 Test (org.junit.Test)82 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)62 LookupExtractionFn (org.apache.druid.query.lookup.LookupExtractionFn)40 RegexDimExtractionFn (org.apache.druid.query.extraction.RegexDimExtractionFn)32 Result (org.apache.druid.query.Result)30 TimeFormatExtractionFn (org.apache.druid.query.extraction.TimeFormatExtractionFn)29 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)27 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)26 JavaScriptExtractionFn (org.apache.druid.query.extraction.JavaScriptExtractionFn)22 SubstringDimExtractionFn (org.apache.druid.query.extraction.SubstringDimExtractionFn)22 StrlenExtractionFn (org.apache.druid.query.extraction.StrlenExtractionFn)21 ExtractionFn (org.apache.druid.query.extraction.ExtractionFn)20 MapLookupExtractor (org.apache.druid.query.extraction.MapLookupExtractor)20 StringFormatExtractionFn (org.apache.druid.query.extraction.StringFormatExtractionFn)20 DimExtractionFn (org.apache.druid.query.extraction.DimExtractionFn)19 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)13 CascadeExtractionFn (org.apache.druid.query.extraction.CascadeExtractionFn)10 SearchQuerySpecDimExtractionFn (org.apache.druid.query.extraction.SearchQuerySpecDimExtractionFn)10 HashMap (java.util.HashMap)8