@Test
  public void testGroupByWithDimFilterAndWithFilteredDimSpec() throws Exception {
    GroupByQuery query =
        GroupByQuery.builder()
            .setDataSource("xx")
            .setQuerySegmentSpec(new LegacySegmentSpec("1970/3000"))
            .setGranularity(QueryGranularity.ALL)
            .setDimensions(
                Lists.<DimensionSpec>newArrayList(
                    new RegexFilteredDimensionSpec(new DefaultDimensionSpec("tags", "tags"), "t3")))
            .setAggregatorSpecs(
                Arrays.asList(new AggregatorFactory[] {new CountAggregatorFactory("count")}))
            .setDimFilter(new SelectorDimFilter("tags", "t3"))
            .build();

    Sequence<Row> result =
        helper.runQueryOnSegmentsObjs(
            ImmutableList.of(
                new QueryableIndexSegment("sid1", queryableIndex),
                new IncrementalIndexSegment(incrementalIndex, "sid2")),
            query);

    List<Row> expectedResults =
        Arrays.asList(
            GroupByQueryRunnerTestHelper.createExpectedRow(
                "1970-01-01T00:00:00.000Z", "tags", "t3", "count", 4L));

    TestHelper.assertExpectedObjects(
        expectedResults, Sequences.toList(result, new ArrayList<Row>()), "");
  }
  @Test
  public void testTopNWithDimFilterAndWithFilteredDimSpec() throws Exception {
    TopNQuery query =
        new TopNQueryBuilder()
            .dataSource("xx")
            .granularity(QueryGranularity.ALL)
            .dimension(
                new ListFilteredDimensionSpec(
                    new DefaultDimensionSpec("tags", "tags"), ImmutableSet.of("t3"), null))
            .metric("count")
            .intervals(QueryRunnerTestHelper.fullOnInterval)
            .aggregators(
                Arrays.asList(new AggregatorFactory[] {new CountAggregatorFactory("count")}))
            .threshold(5)
            .filters(new SelectorDimFilter("tags", "t3"))
            .build();

    QueryRunnerFactory factory =
        new TopNQueryRunnerFactory(
            TestQueryRunners.getPool(),
            new TopNQueryQueryToolChest(
                new TopNQueryConfig(),
                QueryRunnerTestHelper.NoopIntervalChunkingQueryRunnerDecorator()),
            QueryRunnerTestHelper.NOOP_QUERYWATCHER);
    QueryRunner<Result<TopNResultValue>> runner =
        QueryRunnerTestHelper.makeQueryRunner(
            factory, new QueryableIndexSegment("sid1", queryableIndex));
    Map<String, Object> context = Maps.newHashMap();
    Sequence<Result<TopNResultValue>> result = runner.run(query, context);
    List<Result<TopNResultValue>> expectedResults =
        Arrays.asList(
            new Result<TopNResultValue>(
                new DateTime("2011-01-12T00:00:00.000Z"),
                new TopNResultValue(
                    Arrays.<Map<String, Object>>asList(
                        ImmutableMap.<String, Object>of("tags", "t3", "count", 2L)))));
    TestHelper.assertExpectedObjects(
        expectedResults, Sequences.toList(result, new ArrayList<Result<TopNResultValue>>()), "");
  }