Search in sources :

Example 6 with AndDimFilter

use of org.apache.druid.query.filter.AndDimFilter in project druid by druid-io.

the class TimeseriesQueryRunnerTest method testTimeseriesWithMultiDimFilterAndOr.

@Test
public void testTimeseriesWithMultiDimFilterAndOr() {
    AndDimFilter andDimFilter = new AndDimFilter(new SelectorDimFilter(QueryRunnerTestHelper.MARKET_DIMENSION, "spot", null), new OrDimFilter(QueryRunnerTestHelper.QUALITY_DIMENSION, "automotive", "business"));
    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", 2L, "index", 254.4554443359375D, "addRowsIndexConstant", 257.4554443359375D, "uniques", QueryRunnerTestHelper.UNIQUES_2))), new Result<>(DateTimes.of("2011-04-02"), new TimeseriesResultValue(ImmutableMap.of("rows", 2L, "index", 260.4129638671875D, "addRowsIndexConstant", 263.4129638671875D, "uniques", QueryRunnerTestHelper.UNIQUES_2))));
    Iterable<Result<TimeseriesResultValue>> results = runner.run(QueryPlus.wrap(query)).toList();
    assertExpectedResults(expectedResults, results);
}
Also used : AndDimFilter(org.apache.druid.query.filter.AndDimFilter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) OrDimFilter(org.apache.druid.query.filter.OrDimFilter) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 7 with AndDimFilter

use of org.apache.druid.query.filter.AndDimFilter in project druid by druid-io.

the class TimeseriesQueryRunnerTest method testTimeseriesWithNonExistentFilterAndMultiDimAndOr.

@Test
public void testTimeseriesWithNonExistentFilterAndMultiDimAndOr() {
    AndDimFilter andDimFilter = new AndDimFilter(new SelectorDimFilter(QueryRunnerTestHelper.MARKET_DIMENSION, "spot", null), new OrDimFilter(QueryRunnerTestHelper.QUALITY_DIMENSION, "automotive", "business", "billyblank"));
    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", 2L, "index", 254.4554443359375D, "addRowsIndexConstant", 257.4554443359375D, "uniques", QueryRunnerTestHelper.UNIQUES_2))), new Result<>(DateTimes.of("2011-04-02"), new TimeseriesResultValue(ImmutableMap.of("rows", 2L, "index", 260.4129638671875D, "addRowsIndexConstant", 263.4129638671875D, "uniques", QueryRunnerTestHelper.UNIQUES_2))));
    Iterable<Result<TimeseriesResultValue>> results = runner.run(QueryPlus.wrap(query)).toList();
    assertExpectedResults(expectedResults, results);
}
Also used : AndDimFilter(org.apache.druid.query.filter.AndDimFilter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) OrDimFilter(org.apache.druid.query.filter.OrDimFilter) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 8 with AndDimFilter

use of org.apache.druid.query.filter.AndDimFilter in project druid by druid-io.

the class TopNQueryRunnerTest method testTopNWithNonExistentFilterMultiDim.

@Test
public void testTopNWithNonExistentFilterMultiDim() {
    AndDimFilter andDimFilter = new AndDimFilter(new SelectorDimFilter(QueryRunnerTestHelper.MARKET_DIMENSION, "billyblank", null), new SelectorDimFilter(QueryRunnerTestHelper.QUALITY_DIMENSION, "mezzanine", null));
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).filters(andDimFilter).dimension(QueryRunnerTestHelper.MARKET_DIMENSION).metric(QueryRunnerTestHelper.INDEX_METRIC).threshold(4).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).aggregators(commonAggregators).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).build();
    assertExpectedResults(Collections.singletonList(new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Collections.emptyList()))), query);
}
Also used : AndDimFilter(org.apache.druid.query.filter.AndDimFilter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 9 with AndDimFilter

use of org.apache.druid.query.filter.AndDimFilter in project druid by druid-io.

the class TimeseriesQueryRunnerTest method testTimeseriesWithNonExistentFilterAndMultiDim.

@Test
public void testTimeseriesWithNonExistentFilterAndMultiDim() {
    AndDimFilter andDimFilter = new AndDimFilter(new SelectorDimFilter(QueryRunnerTestHelper.MARKET_DIMENSION, "billy", null), new SelectorDimFilter(QueryRunnerTestHelper.QUALITY_DIMENSION, "business", 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();
    Map<String, Object> resultMap = new HashMap<>();
    resultMap.put("rows", 0L);
    resultMap.put("index", NullHandling.defaultDoubleValue());
    resultMap.put("addRowsIndexConstant", NullHandling.replaceWithDefault() ? 1.0 : null);
    resultMap.put("uniques", 0.0);
    List<Result<TimeseriesResultValue>> expectedResults = Arrays.asList(new Result<>(DateTimes.of("2011-04-01"), new TimeseriesResultValue(resultMap)), new Result<>(DateTimes.of("2011-04-02"), new TimeseriesResultValue(resultMap)));
    Iterable<Result<TimeseriesResultValue>> results = runner.run(QueryPlus.wrap(query)).toList();
    assertExpectedResults(expectedResults, results);
}
Also used : AndDimFilter(org.apache.druid.query.filter.AndDimFilter) HashMap(java.util.HashMap) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 10 with AndDimFilter

use of org.apache.druid.query.filter.AndDimFilter in project druid by druid-io.

the class TimeseriesQueryRunnerTest method testTimeseriesWithMultiValueDimFilterAndOr1.

@Test
public void testTimeseriesWithMultiValueDimFilterAndOr1() {
    AndDimFilter andDimFilter = new AndDimFilter(new SelectorDimFilter(QueryRunnerTestHelper.MARKET_DIMENSION, "spot", null), new SelectorDimFilter(QueryRunnerTestHelper.PLACEMENTISH_DIMENSION, "a", 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();
    AndDimFilter andDimFilter2 = new AndDimFilter(new SelectorDimFilter(QueryRunnerTestHelper.MARKET_DIMENSION, "spot", null), new SelectorDimFilter(QueryRunnerTestHelper.QUALITY_DIMENSION, "automotive", null));
    TimeseriesQuery query2 = Druids.newTimeseriesQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.DAY_GRAN).filters(andDimFilter2).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).aggregators(aggregatorFactoryList).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).descending(descending).context(makeContext()).build();
    Iterable<Result<TimeseriesResultValue>> expectedResults = runner.run(QueryPlus.wrap(query2)).toList();
    Iterable<Result<TimeseriesResultValue>> actualResults = runner.run(QueryPlus.wrap(query)).toList();
    TestHelper.assertExpectedResults(expectedResults, actualResults);
}
Also used : AndDimFilter(org.apache.druid.query.filter.AndDimFilter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

AndDimFilter (org.apache.druid.query.filter.AndDimFilter)43 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)35 Test (org.junit.Test)28 DimFilter (org.apache.druid.query.filter.DimFilter)23 OrDimFilter (org.apache.druid.query.filter.OrDimFilter)23 BoundDimFilter (org.apache.druid.query.filter.BoundDimFilter)21 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)18 ArrayList (java.util.ArrayList)15 InDimFilter (org.apache.druid.query.filter.InDimFilter)10 Result (org.apache.druid.query.Result)9 NotDimFilter (org.apache.druid.query.filter.NotDimFilter)9 List (java.util.List)6 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)6 FinalizeResultsQueryRunner (org.apache.druid.query.FinalizeResultsQueryRunner)5 QueryRunner (org.apache.druid.query.QueryRunner)5 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)5 HashMap (java.util.HashMap)4 Druids (org.apache.druid.query.Druids)4 TimeseriesQueryQueryToolChest (org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest)4 QueryableDruidServer (org.apache.druid.client.selector.QueryableDruidServer)3