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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations