Search in sources :

Example 1 with AndDimFilter

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

the class FilterPartitionTest method testDistributeOrCNFExtractionFn.

@Test
public void testDistributeOrCNFExtractionFn() {
    DimFilter dimFilter1 = new OrDimFilter(Arrays.asList(new SelectorDimFilter("dim0", "super-6", JS_EXTRACTION_FN), new AndDimFilter(Arrays.asList(new NoBitmapSelectorDimFilter("dim1", "super-abdef", JS_EXTRACTION_FN), new SelectorDimFilter("dim2", "super-c", JS_EXTRACTION_FN)))));
    Filter filter1 = dimFilter1.toFilter();
    Filter filter1CNF = Filters.toCnf(filter1);
    Assert.assertEquals(AndFilter.class, filter1CNF.getClass());
    Assert.assertEquals(2, ((AndFilter) filter1CNF).getFilters().size());
    assertFilterMatches(dimFilter1, ImmutableList.of("4", "6"));
    DimFilter dimFilter2 = new OrDimFilter(Arrays.asList(new SelectorDimFilter("dim0", "super-2", JS_EXTRACTION_FN), new SelectorDimFilter("dim0", "super-3", JS_EXTRACTION_FN), new AndDimFilter(Arrays.asList(new NoBitmapSelectorDimFilter("dim1", "super-HELLO", JS_EXTRACTION_FN), new SelectorDimFilter("dim2", "super-foo", JS_EXTRACTION_FN)))));
    assertFilterMatches(dimFilter2, ImmutableList.of("2", "3", "7"));
    DimFilter dimFilter3 = new OrDimFilter(dimFilter1, dimFilter2, new AndDimFilter(new NoBitmapSelectorDimFilter("dim1", "super-1", JS_EXTRACTION_FN), new SelectorDimFilter("dim2", "super-foo", JS_EXTRACTION_FN)));
    assertFilterMatches(dimFilter3, ImmutableList.of("2", "3", "4", "6", "7", "9"));
}
Also used : AndDimFilter(org.apache.druid.query.filter.AndDimFilter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) AndDimFilter(org.apache.druid.query.filter.AndDimFilter) DimFilter(org.apache.druid.query.filter.DimFilter) OrDimFilter(org.apache.druid.query.filter.OrDimFilter) Filter(org.apache.druid.query.filter.Filter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) OrDimFilter(org.apache.druid.query.filter.OrDimFilter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) AndDimFilter(org.apache.druid.query.filter.AndDimFilter) DimFilter(org.apache.druid.query.filter.DimFilter) OrDimFilter(org.apache.druid.query.filter.OrDimFilter) Test(org.junit.Test)

Example 2 with AndDimFilter

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

the class AndFilterTest method testAnd.

@Test
public void testAnd() {
    assertFilterMatches(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "0", null), new SelectorDimFilter("dim1", "0", null))), ImmutableList.of("0"));
    assertFilterMatches(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "0", null), new SelectorDimFilter("dim1", "1", null))), ImmutableList.of());
    assertFilterMatches(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "1", null), new SelectorDimFilter("dim1", "0", null))), ImmutableList.of("1"));
    assertFilterMatches(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "1", null), new SelectorDimFilter("dim1", "1", null))), ImmutableList.of());
    assertFilterMatches(new AndDimFilter(ImmutableList.of(new NotDimFilter(new SelectorDimFilter("dim0", "1", null)), new NotDimFilter(new SelectorDimFilter("dim1", "1", null)))), ImmutableList.of("0", "2", "3", "4", "5"));
    assertFilterMatches(new AndDimFilter(ImmutableList.of(new NotDimFilter(new SelectorDimFilter("dim0", "0", null)), new NotDimFilter(new SelectorDimFilter("dim1", "0", null)))), ImmutableList.of());
}
Also used : NotDimFilter(org.apache.druid.query.filter.NotDimFilter) AndDimFilter(org.apache.druid.query.filter.AndDimFilter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) Test(org.junit.Test)

Example 3 with AndDimFilter

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

the class AndFilterTest method testNotAnd.

@Test
public void testNotAnd() {
    assertFilterMatches(new NotDimFilter(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "0", null), new SelectorDimFilter("dim1", "0", null)))), ImmutableList.of("1", "2", "3", "4", "5"));
    assertFilterMatches(new NotDimFilter(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "0", null), new SelectorDimFilter("dim1", "1", null)))), ImmutableList.of("0", "1", "2", "3", "4", "5"));
    assertFilterMatches(new NotDimFilter(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "1", null), new SelectorDimFilter("dim1", "0", null)))), ImmutableList.of("0", "2", "3", "4", "5"));
    assertFilterMatches(new NotDimFilter(new AndDimFilter(ImmutableList.of(new SelectorDimFilter("dim0", "1", null), new SelectorDimFilter("dim1", "1", null)))), ImmutableList.of("0", "1", "2", "3", "4", "5"));
    assertFilterMatches(new NotDimFilter(new AndDimFilter(ImmutableList.of(new NotDimFilter(new SelectorDimFilter("dim0", "1", null)), new NotDimFilter(new SelectorDimFilter("dim1", "1", null))))), ImmutableList.of("1"));
    assertFilterMatches(new NotDimFilter(new AndDimFilter(ImmutableList.of(new NotDimFilter(new SelectorDimFilter("dim0", "0", null)), new NotDimFilter(new SelectorDimFilter("dim1", "0", null))))), ImmutableList.of("0", "1", "2", "3", "4", "5"));
}
Also used : NotDimFilter(org.apache.druid.query.filter.NotDimFilter) AndDimFilter(org.apache.druid.query.filter.AndDimFilter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) Test(org.junit.Test)

Example 4 with AndDimFilter

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

the class GroupByQueryRunnerTest method testGroupByWithHavingSpecOnLongAndFloat.

@Test
public void testGroupByWithHavingSpecOnLongAndFloat() {
    if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
        expectedException.expect(UnsupportedOperationException.class);
        expectedException.expectMessage("GroupBy v1 only supports dimensions with an outputType of STRING.");
    }
    GroupByQuery query = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("market", "alias"), new DefaultDimensionSpec("qualityLong", "ql_alias", ColumnType.LONG), new DefaultDimensionSpec("__time", "time_alias", ColumnType.LONG), new DefaultDimensionSpec("index", "index_alias", ColumnType.FLOAT)).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT).setHavingSpec(new DimFilterHavingSpec(new AndDimFilter(Lists.newArrayList(new SelectorDimFilter("ql_alias", "1400", null), new SelectorDimFilter("time_alias", "1301616000000", null), new BoundDimFilter("index_alias", "1310.0", "1320.0", true, true, null, null, StringComparators.NUMERIC))), null)).setGranularity(QueryRunnerTestHelper.ALL_GRAN).build();
    List<ResultRow> expectedResults = Collections.singletonList(makeRow(query, "2011-04-01", "alias", "total_market", "time_alias", 1301616000000L, "index_alias", 1314.8397, "ql_alias", 1400L, "rows", 1L));
    Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
    TestHelper.assertExpectedObjects(expectedResults, results, "havingspec-long-float");
}
Also used : DimFilterHavingSpec(org.apache.druid.query.groupby.having.DimFilterHavingSpec) BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) AndDimFilter(org.apache.druid.query.filter.AndDimFilter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 5 with AndDimFilter

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

the class GroupByQueryQueryToolChestTest method testResultLevelCacheKeyWithHavingDimFilterHavingSpec.

@Test
public void testResultLevelCacheKeyWithHavingDimFilterHavingSpec() {
    final DimFilterHavingSpec havingSpec1 = new DimFilterHavingSpec(new AndDimFilter(ImmutableList.of(new OrDimFilter(ImmutableList.of(new BoundDimFilter("rows", "2", null, true, false, null, null, StringComparators.NUMERIC), new SelectorDimFilter("idx", "217", null))), new SelectorDimFilter("__time", String.valueOf(DateTimes.of("2011-04-01").getMillis()), null))), null);
    final DimFilterHavingSpec havingSpec2 = new DimFilterHavingSpec(new AndDimFilter(ImmutableList.of(new OrDimFilter(ImmutableList.of(new BoundDimFilter("rows", "2", null, true, false, null, null, StringComparators.NUMERIC), new SelectorDimFilter("idx", "317", null))), new SelectorDimFilter("__time", String.valueOf(DateTimes.of("2011-04-01").getMillis()), null))), null);
    final GroupByQuery query1 = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("quality", "alias")).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index")).setPostAggregatorSpecs(ImmutableList.of(new ExpressionPostAggregator("post", "alias + 'x'", null, TestExprMacroTable.INSTANCE))).setGranularity(QueryRunnerTestHelper.DAY_GRAN).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("post", OrderByColumnSpec.Direction.DESCENDING)), Integer.MAX_VALUE)).setHavingSpec(havingSpec1).build();
    final GroupByQuery query2 = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("quality", "alias")).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index")).setPostAggregatorSpecs(ImmutableList.of(new ExpressionPostAggregator("post", "alias + 'x'", null, TestExprMacroTable.INSTANCE))).setGranularity(QueryRunnerTestHelper.DAY_GRAN).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("post", OrderByColumnSpec.Direction.DESCENDING)), Integer.MAX_VALUE)).setHavingSpec(havingSpec2).build();
    final CacheStrategy<ResultRow, Object, GroupByQuery> strategy1 = new GroupByQueryQueryToolChest(null).getCacheStrategy(query1);
    final CacheStrategy<ResultRow, Object, GroupByQuery> strategy2 = new GroupByQueryQueryToolChest(null).getCacheStrategy(query2);
    Assert.assertTrue(Arrays.equals(strategy1.computeCacheKey(query1), strategy2.computeCacheKey(query2)));
    Assert.assertFalse(Arrays.equals(strategy1.computeResultLevelCacheKey(query1), strategy2.computeResultLevelCacheKey(query2)));
}
Also used : DimFilterHavingSpec(org.apache.druid.query.groupby.having.DimFilterHavingSpec) BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) AndDimFilter(org.apache.druid.query.filter.AndDimFilter) DefaultLimitSpec(org.apache.druid.query.groupby.orderby.DefaultLimitSpec) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) OrderByColumnSpec(org.apache.druid.query.groupby.orderby.OrderByColumnSpec) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) ExpressionPostAggregator(org.apache.druid.query.aggregation.post.ExpressionPostAggregator) OrDimFilter(org.apache.druid.query.filter.OrDimFilter) 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