use of org.apache.druid.query.dimension.ListFilteredDimensionSpec in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByNumericStringsAsNumericWithDecoration.
@Test
public void testGroupByNumericStringsAsNumericWithDecoration() {
// Cannot vectorize due to regex-filtered dimension spec.
cannotVectorize();
if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("GroupBy v1 only supports dimensions with an outputType of STRING.");
}
// rows with `technology` have `170000` in the qualityNumericString field
RegexFilteredDimensionSpec regexSpec = new RegexFilteredDimensionSpec(new DefaultDimensionSpec("qualityNumericString", "ql", ColumnType.LONG), "170000");
ListFilteredDimensionSpec listFilteredSpec = new ListFilteredDimensionSpec(new DefaultDimensionSpec("qualityNumericString", "qf", ColumnType.FLOAT), Sets.newHashSet("170000"), true);
GroupByQuery query = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(regexSpec, listFilteredSpec).setDimFilter(new InDimFilter("quality", Arrays.asList("entertainment", "technology"), null)).setAggregatorSpecs(new CountAggregatorFactory("count")).setGranularity(QueryRunnerTestHelper.ALL_GRAN).addOrderByColumn("ql").build();
List<ResultRow> expectedResults;
// "entertainment" rows are excluded by the decorated specs, they become empty rows
expectedResults = Arrays.asList(makeRow(query, "2011-04-01", "ql", NullHandling.defaultLongValue(), "qf", NullHandling.defaultDoubleValue(), "count", 2L), makeRow(query, "2011-04-01", "ql", 170000L, "qf", 170000.0, "count", 2L));
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "numeric-string");
}
use of org.apache.druid.query.dimension.ListFilteredDimensionSpec in project druid by druid-io.
the class TopNQueryRunnerTest method testFullOnTopNNumericStringColumnWithDecoration.
@Test
public void testFullOnTopNNumericStringColumnWithDecoration() {
ListFilteredDimensionSpec filteredSpec = new ListFilteredDimensionSpec(new DefaultDimensionSpec("qualityNumericString", "qns_alias", ColumnType.LONG), Sets.newHashSet("120000", "140000", "160000"), true);
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(filteredSpec).metric("maxIndex").threshold(4).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).aggregators(Lists.newArrayList(Iterables.concat(commonAggregators, Lists.newArrayList(new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index"))))).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.<String, Object>builder().put("qns_alias", 140000L).put(QueryRunnerTestHelper.INDEX_METRIC, 217725.41940800005D).put("rows", 279L).put("addRowsIndexConstant", 218005.41940800005D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 1870.061029D).put("minIndex", 91.270553D).build(), ImmutableMap.<String, Object>builder().put("qns_alias", 160000L).put(QueryRunnerTestHelper.INDEX_METRIC, 210865.67977600006D).put("rows", 279L).put("addRowsIndexConstant", 211145.67977600006D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 1862.737933D).put("minIndex", 99.284525D).build(), ImmutableMap.<String, Object>builder().put("qns_alias", 120000L).put(QueryRunnerTestHelper.INDEX_METRIC, 12086.472791D).put("rows", 93L).put("addRowsIndexConstant", 12180.472791D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 193.787574D).put("minIndex", 84.710523D).build()))));
assertExpectedResults(expectedResults, query);
}
use of org.apache.druid.query.dimension.ListFilteredDimensionSpec in project druid by druid-io.
the class DefaultSearchQueryMetricsTest method testDefaultSearchQueryMetricsQuery.
/**
* Tests that passed a query {@link DefaultSearchQueryMetrics} produces events with a certain set of dimensions.
*/
@Test
public void testDefaultSearchQueryMetricsQuery() {
CachingEmitter cachingEmitter = new CachingEmitter();
ServiceEmitter serviceEmitter = new ServiceEmitter("", "", cachingEmitter);
SearchQuery query = Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.DAY_GRAN).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).dimensions(new ListFilteredDimensionSpec(new DefaultDimensionSpec("tags", "tags"), ImmutableSet.of("t3"), null)).context(ImmutableMap.of("testKey", "testValue")).build();
SearchQueryMetrics queryMetrics = DefaultSearchQueryMetricsFactory.instance().makeMetrics(query);
queryMetrics.query(query);
queryMetrics.reportQueryTime(0).emit(serviceEmitter);
Map<String, Object> actualEvent = cachingEmitter.getLastEmittedEvent().toMap();
Assert.assertEquals(13, actualEvent.size());
Assert.assertTrue(actualEvent.containsKey("feed"));
Assert.assertTrue(actualEvent.containsKey("timestamp"));
Assert.assertEquals("", actualEvent.get("host"));
Assert.assertEquals("", actualEvent.get("service"));
Assert.assertEquals(QueryRunnerTestHelper.DATA_SOURCE, actualEvent.get(DruidMetrics.DATASOURCE));
Assert.assertEquals(query.getType(), actualEvent.get(DruidMetrics.TYPE));
List<Interval> expectedIntervals = QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC.getIntervals();
List<String> expectedStringIntervals = expectedIntervals.stream().map(Interval::toString).collect(Collectors.toList());
Assert.assertEquals(expectedStringIntervals, actualEvent.get(DruidMetrics.INTERVAL));
Assert.assertEquals("false", actualEvent.get("hasFilters"));
Assert.assertEquals(expectedIntervals.get(0).toDuration().toString(), actualEvent.get("duration"));
Assert.assertEquals("", actualEvent.get(DruidMetrics.ID));
Assert.assertEquals(ImmutableMap.of("testKey", "testValue"), actualEvent.get("context"));
// Metric
Assert.assertEquals("query/time", actualEvent.get("metric"));
Assert.assertEquals(0L, actualEvent.get("value"));
}
use of org.apache.druid.query.dimension.ListFilteredDimensionSpec in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByDecorationOnNumerics.
@Test
public void testGroupByDecorationOnNumerics() {
// Cannot vectorize due to filtered dimension spec.
cannotVectorize();
if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("GroupBy v1 only supports dimensions with an outputType of STRING.");
}
RegexFilteredDimensionSpec regexSpec = new RegexFilteredDimensionSpec(new DefaultDimensionSpec("qualityLong", "ql", ColumnType.LONG), "1700");
ListFilteredDimensionSpec listFilteredSpec = new ListFilteredDimensionSpec(new DefaultDimensionSpec("qualityFloat", "qf", ColumnType.FLOAT), Sets.newHashSet("17000.0"), true);
GroupByQuery query = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(regexSpec, listFilteredSpec).setDimFilter(new InDimFilter("quality", Arrays.asList("entertainment", "technology"), null)).setAggregatorSpecs(new CountAggregatorFactory("count")).setGranularity(QueryRunnerTestHelper.ALL_GRAN).build();
List<ResultRow> expectedResults;
if (NullHandling.replaceWithDefault()) {
expectedResults = Arrays.asList(makeRow(query, "2011-04-01", "ql", 0L, "qf", 0.0, "count", 2L), makeRow(query, "2011-04-01", "ql", 1700L, "qf", 17000.0, "count", 2L));
} else {
expectedResults = Arrays.asList(makeRow(query, "2011-04-01", "ql", null, "qf", null, "count", 2L), makeRow(query, "2011-04-01", "ql", 1700L, "qf", 17000.0, "count", 2L));
}
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "numeric");
}
use of org.apache.druid.query.dimension.ListFilteredDimensionSpec in project druid by druid-io.
the class MultiValuedDimensionTest method testTopNWithDimFilterAndWithFilteredDimSpec.
@Test
public void testTopNWithDimFilterAndWithFilteredDimSpec() {
TopNQuery query = new TopNQueryBuilder().dataSource("xx").granularity(Granularities.ALL).dimension(new ListFilteredDimensionSpec(new DefaultDimensionSpec("tags", "tags"), ImmutableSet.of("t3"), null)).metric("count").intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).aggregators(new CountAggregatorFactory("count")).threshold(5).filters(new SelectorDimFilter("tags", "t3", null)).build();
try (CloseableStupidPool<ByteBuffer> pool = TestQueryRunners.createDefaultNonBlockingPool()) {
QueryRunnerFactory factory = new TopNQueryRunnerFactory(pool, new TopNQueryQueryToolChest(new TopNQueryConfig()), QueryRunnerTestHelper.NOOP_QUERYWATCHER);
QueryRunner<Result<TopNResultValue>> runner = QueryRunnerTestHelper.makeQueryRunner(factory, new QueryableIndexSegment(queryableIndex, SegmentId.dummy("sid1")), null);
Sequence<Result<TopNResultValue>> result = runner.run(QueryPlus.wrap(query));
List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<TopNResultValue>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(Collections.<Map<String, Object>>singletonList(ImmutableMap.of("tags", "t3", "count", 2L)))));
TestHelper.assertExpectedObjects(expectedResults, result.toList(), "filteredDim");
}
}
Aggregations