Search in sources :

Example 1 with AndHavingSpec

use of org.apache.druid.query.groupby.having.AndHavingSpec in project druid by druid-io.

the class GroupByQueryQueryToolChestTest method testResultLevelCacheKeyWithAndHavingSpec.

@Test
public void testResultLevelCacheKeyWithAndHavingSpec() {
    final List<HavingSpec> havings = Arrays.asList(new GreaterThanHavingSpec("agg", Double.valueOf(1.3)), new OrHavingSpec(Arrays.asList(new LessThanHavingSpec("lessAgg", Long.valueOf(1L)), new NotHavingSpec(new EqualToHavingSpec("equalAgg", Double.valueOf(2))))));
    final HavingSpec andHavingSpec = new AndHavingSpec(havings);
    final List<HavingSpec> havings2 = Arrays.asList(new GreaterThanHavingSpec("agg", Double.valueOf(13.0)), new OrHavingSpec(Arrays.asList(new LessThanHavingSpec("lessAgg", Long.valueOf(1L)), new NotHavingSpec(new EqualToHavingSpec("equalAgg", Double.valueOf(22))))));
    final HavingSpec andHavingSpec2 = new AndHavingSpec(havings2);
    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(andHavingSpec).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(andHavingSpec2).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 : EqualToHavingSpec(org.apache.druid.query.groupby.having.EqualToHavingSpec) OrHavingSpec(org.apache.druid.query.groupby.having.OrHavingSpec) DefaultLimitSpec(org.apache.druid.query.groupby.orderby.DefaultLimitSpec) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) LessThanHavingSpec(org.apache.druid.query.groupby.having.LessThanHavingSpec) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) OrderByColumnSpec(org.apache.druid.query.groupby.orderby.OrderByColumnSpec) AndHavingSpec(org.apache.druid.query.groupby.having.AndHavingSpec) DimFilterHavingSpec(org.apache.druid.query.groupby.having.DimFilterHavingSpec) NotHavingSpec(org.apache.druid.query.groupby.having.NotHavingSpec) LessThanHavingSpec(org.apache.druid.query.groupby.having.LessThanHavingSpec) HavingSpec(org.apache.druid.query.groupby.having.HavingSpec) OrHavingSpec(org.apache.druid.query.groupby.having.OrHavingSpec) AndHavingSpec(org.apache.druid.query.groupby.having.AndHavingSpec) EqualToHavingSpec(org.apache.druid.query.groupby.having.EqualToHavingSpec) GreaterThanHavingSpec(org.apache.druid.query.groupby.having.GreaterThanHavingSpec) ExpressionPostAggregator(org.apache.druid.query.aggregation.post.ExpressionPostAggregator) GreaterThanHavingSpec(org.apache.druid.query.groupby.having.GreaterThanHavingSpec) NotHavingSpec(org.apache.druid.query.groupby.having.NotHavingSpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)1 ExpressionPostAggregator (org.apache.druid.query.aggregation.post.ExpressionPostAggregator)1 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)1 AndHavingSpec (org.apache.druid.query.groupby.having.AndHavingSpec)1 DimFilterHavingSpec (org.apache.druid.query.groupby.having.DimFilterHavingSpec)1 EqualToHavingSpec (org.apache.druid.query.groupby.having.EqualToHavingSpec)1 GreaterThanHavingSpec (org.apache.druid.query.groupby.having.GreaterThanHavingSpec)1 HavingSpec (org.apache.druid.query.groupby.having.HavingSpec)1 LessThanHavingSpec (org.apache.druid.query.groupby.having.LessThanHavingSpec)1 NotHavingSpec (org.apache.druid.query.groupby.having.NotHavingSpec)1 OrHavingSpec (org.apache.druid.query.groupby.having.OrHavingSpec)1 DefaultLimitSpec (org.apache.druid.query.groupby.orderby.DefaultLimitSpec)1 OrderByColumnSpec (org.apache.druid.query.groupby.orderby.OrderByColumnSpec)1 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)1 Test (org.junit.Test)1