use of org.apache.druid.query.filter.AndDimFilter in project druid by druid-io.
the class SearchBenchmark method basicC.
private static SearchQueryBuilder basicC(final GeneratorSchemaInfo basicSchema) {
final QuerySegmentSpec intervalSpec = new MultipleIntervalSegmentSpec(Collections.singletonList(basicSchema.getDataInterval()));
final List<String> dimUniformFilterVals = new ArrayList<>();
final int resultNum = (int) (100000 * 0.1);
final int step = 100000 / resultNum;
for (int i = 1; i < 100001 && dimUniformFilterVals.size() < resultNum; i += step) {
dimUniformFilterVals.add(String.valueOf(i));
}
final String dimName = "dimUniform";
final List<DimFilter> dimFilters = new ArrayList<>();
dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, IdentityExtractionFn.getInstance()));
dimFilters.add(new SelectorDimFilter(dimName, "3", StrlenExtractionFn.instance()));
dimFilters.add(new BoundDimFilter(dimName, "100", "10000", true, true, true, new DimExtractionFn() {
@Override
public byte[] getCacheKey() {
return new byte[] { 0xF };
}
@Override
public String apply(String value) {
return String.valueOf(Long.parseLong(value) + 1);
}
@Override
public boolean preservesOrdering() {
return false;
}
@Override
public ExtractionType getExtractionType() {
return ExtractionType.ONE_TO_ONE;
}
}, null));
dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, new LowerExtractionFn(null)));
dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, new UpperExtractionFn(null)));
dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, new SubstringDimExtractionFn(1, 3)));
return Druids.newSearchQueryBuilder().dataSource("blah").granularity(Granularities.ALL).intervals(intervalSpec).query("").dimensions(Collections.singletonList("dimUniform")).filters(new AndDimFilter(dimFilters));
}
use of org.apache.druid.query.filter.AndDimFilter in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByNestedWithInnerQueryNumerics.
@Test
public void testGroupByNestedWithInnerQueryNumerics() {
if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("GroupBy v1 only supports dimensions with an outputType of STRING.");
}
GroupByQuery subquery = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("quality", "alias"), new DefaultDimensionSpec("qualityLong", "ql_alias", ColumnType.LONG), new DefaultDimensionSpec("qualityFloat", "qf_alias", ColumnType.FLOAT)).setDimFilter(new InDimFilter("quality", Collections.singletonList("entertainment"), null)).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
GroupByQuery outerQuery = makeQueryBuilder().setDataSource(subquery).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("ql_alias", "quallong", ColumnType.LONG), new DefaultDimensionSpec("qf_alias", "qualfloat", ColumnType.FLOAT)).setDimFilter(new AndDimFilter(Lists.newArrayList(new SelectorDimFilter("ql_alias", "1200", null), new BoundDimFilter("qf_alias", "11095.0", "12005.0", true, true, null, null, StringComparators.NUMERIC)))).setAggregatorSpecs(new LongSumAggregatorFactory("ql_alias_sum", "ql_alias"), new DoubleSumAggregatorFactory("qf_alias_sum", "qf_alias")).setGranularity(QueryRunnerTestHelper.ALL_GRAN).build();
List<ResultRow> expectedResults = Collections.singletonList(makeRow(outerQuery, "2011-04-01", "quallong", 1200L, "qualfloat", 12000.0, "ql_alias_sum", 2400L, "qf_alias_sum", 24000.0));
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, outerQuery);
TestHelper.assertExpectedObjects(expectedResults, results, "numerics");
}
use of org.apache.druid.query.filter.AndDimFilter in project druid by druid-io.
the class TransformSpecTest method testFilterOnTransforms.
@Test
public void testFilterOnTransforms() {
// Filters are allowed to refer to transformed fields; double-check this.
final TransformSpec transformSpec = new TransformSpec(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("x", "foo", null), new SelectorDimFilter("f", "foobar", null), new SelectorDimFilter("g", "5.0", null))), ImmutableList.of(new ExpressionTransform("f", "concat(x,y)", TestExprMacroTable.INSTANCE), new ExpressionTransform("g", "a + b", TestExprMacroTable.INSTANCE)));
Assert.assertEquals(ImmutableSet.of("x", "f", "g", "y", "a", "b"), transformSpec.getRequiredColumns());
final InputRowParser<Map<String, Object>> parser = transformSpec.decorate(PARSER);
Assert.assertNotNull(parser.parseBatch(ROW1).get(0));
Assert.assertNull(parser.parseBatch(ROW2).get(0));
}
use of org.apache.druid.query.filter.AndDimFilter in project druid by druid-io.
the class SearchQueryRunnerTest method testSearchWithFilterEmptyResults.
@Test
public void testSearchWithFilterEmptyResults() {
List<SearchHit> expectedHits = new ArrayList<>();
DimFilter filter = new AndDimFilter(new SelectorDimFilter(QueryRunnerTestHelper.MARKET_DIMENSION, "total_market", null), new SelectorDimFilter(QueryRunnerTestHelper.QUALITY_DIMENSION, "automotive", null));
checkSearchQuery(Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).filters(filter).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).query("a").build(), expectedHits);
}
use of org.apache.druid.query.filter.AndDimFilter in project druid by druid-io.
the class TimeseriesQueryRunnerTest method testTimeseriesWithMultiDimFilter.
@Test
public void testTimeseriesWithMultiDimFilter() {
AndDimFilter andDimFilter = new AndDimFilter(new SelectorDimFilter(QueryRunnerTestHelper.MARKET_DIMENSION, "spot", null), new SelectorDimFilter(QueryRunnerTestHelper.QUALITY_DIMENSION, "automotive", null));
TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.DAY_GRAN).filters(andDimFilter).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).aggregators(aggregatorFactoryList).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).descending(descending).context(makeContext()).build();
List<Result<TimeseriesResultValue>> expectedResults = Arrays.asList(new Result<>(DateTimes.of("2011-04-01"), new TimeseriesResultValue(ImmutableMap.of("rows", 1L, "index", new Float(135.885094).doubleValue(), "addRowsIndexConstant", new Float(137.885094).doubleValue(), "uniques", QueryRunnerTestHelper.UNIQUES_1))), new Result<>(DateTimes.of("2011-04-02"), new TimeseriesResultValue(ImmutableMap.of("rows", 1L, "index", new Float(147.425935).doubleValue(), "addRowsIndexConstant", new Float(149.425935).doubleValue(), "uniques", QueryRunnerTestHelper.UNIQUES_1))));
Iterable<Result<TimeseriesResultValue>> results = runner.run(QueryPlus.wrap(query)).toList();
assertExpectedResults(expectedResults, results);
}
Aggregations