Search in sources :

Example 6 with LegacySegmentSpec

use of io.druid.query.spec.LegacySegmentSpec in project druid by druid-io.

the class SelectQuerySpecTest method testPagingSpecFromNext.

@Test
public void testPagingSpecFromNext() throws Exception {
    String baseQueryJson = "{\"queryType\":\"select\",\"dataSource\":{\"type\":\"table\",\"name\":\"testing\"}," + "\"intervals\":{\"type\":\"LegacySegmentSpec\",\"intervals\":[\"2011-01-12T00:00:00.000Z/2011-01-14T00:00:00.000Z\"]}," + "\"descending\":true," + "\"filter\":null," + "\"granularity\":{\"type\":\"all\"}," + "\"dimensions\":" + "[{\"type\":\"default\",\"dimension\":\"market\",\"outputName\":\"market\",\"outputType\":\"STRING\"}," + "{\"type\":\"default\",\"dimension\":\"quality\",\"outputName\":\"quality\",\"outputType\":\"STRING\"}]," + "\"metrics\":[\"index\"]," + "\"virtualColumns\":[],";
    String withNull = baseQueryJson + "\"pagingSpec\":{\"pagingIdentifiers\":{},\"threshold\":3,\"fromNext\":null}," + "\"context\":null}";
    String withFalse = baseQueryJson + "\"pagingSpec\":{\"pagingIdentifiers\":{},\"threshold\":3,\"fromNext\":false}," + "\"context\":null}";
    String withTrue = baseQueryJson + "\"pagingSpec\":{\"pagingIdentifiers\":{},\"threshold\":3,\"fromNext\":true}," + "\"context\":null}";
    SelectQuery queryWithNull = new SelectQuery(new TableDataSource(QueryRunnerTestHelper.dataSource), new LegacySegmentSpec(new Interval("2011-01-12/2011-01-14")), true, null, QueryRunnerTestHelper.allGran, DefaultDimensionSpec.toSpec(Arrays.<String>asList("market", "quality")), Arrays.<String>asList("index"), null, new PagingSpec(null, 3, null), null);
    SelectQuery queryWithFalse = queryWithNull.withPagingSpec(new PagingSpec(null, 3, false));
    SelectQuery queryWithTrue = queryWithNull.withPagingSpec(new PagingSpec(null, 3, true));
    String actualWithNull = objectMapper.writeValueAsString(queryWithNull);
    Assert.assertEquals(withTrue, actualWithNull);
    String actualWithFalse = objectMapper.writeValueAsString(queryWithFalse);
    Assert.assertEquals(withFalse, actualWithFalse);
    String actualWithTrue = objectMapper.writeValueAsString(queryWithTrue);
    Assert.assertEquals(withTrue, actualWithTrue);
    Assert.assertEquals(queryWithNull, objectMapper.readValue(actualWithNull, SelectQuery.class));
    Assert.assertEquals(queryWithFalse, objectMapper.readValue(actualWithFalse, SelectQuery.class));
    Assert.assertEquals(queryWithTrue, objectMapper.readValue(actualWithTrue, SelectQuery.class));
}
Also used : TableDataSource(io.druid.query.TableDataSource) LegacySegmentSpec(io.druid.query.spec.LegacySegmentSpec) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 7 with LegacySegmentSpec

use of io.druid.query.spec.LegacySegmentSpec in project druid by druid-io.

the class MultiValuedDimensionTest method testGroupByWithDimFilterAndWithFilteredDimSpec.

@Test
public void testGroupByWithDimFilterAndWithFilteredDimSpec() throws Exception {
    GroupByQuery query = GroupByQuery.builder().setDataSource("xx").setQuerySegmentSpec(new LegacySegmentSpec("1970/3000")).setGranularity(Granularities.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", null)).build();
    Sequence<Row> result = helper.runQueryOnSegmentsObjs(ImmutableList.<Segment>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>()), "");
}
Also used : QueryableIndexSegment(io.druid.segment.QueryableIndexSegment) ListFilteredDimensionSpec(io.druid.query.dimension.ListFilteredDimensionSpec) DimensionSpec(io.druid.query.dimension.DimensionSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) IncrementalIndexSegment(io.druid.segment.IncrementalIndexSegment) ArrayList(java.util.ArrayList) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) LegacySegmentSpec(io.druid.query.spec.LegacySegmentSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) GroupByQuery(io.druid.query.groupby.GroupByQuery) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) Row(io.druid.data.input.Row) GroupByQueryRunnerTest(io.druid.query.groupby.GroupByQueryRunnerTest) Test(org.junit.Test)

Aggregations

LegacySegmentSpec (io.druid.query.spec.LegacySegmentSpec)7 Test (org.junit.Test)7 Row (io.druid.data.input.Row)4 CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)4 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)4 ArrayList (java.util.ArrayList)4 TableDataSource (io.druid.query.TableDataSource)3 GroupByQuery (io.druid.query.groupby.GroupByQuery)3 GroupByQueryRunnerTest (io.druid.query.groupby.GroupByQueryRunnerTest)3 IncrementalIndexSegment (io.druid.segment.IncrementalIndexSegment)3 QueryableIndexSegment (io.druid.segment.QueryableIndexSegment)3 Interval (org.joda.time.Interval)3 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)2 DimensionSpec (io.druid.query.dimension.DimensionSpec)2 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)2 RegexFilteredDimensionSpec (io.druid.query.dimension.RegexFilteredDimensionSpec)2 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)2 MergeSequence (io.druid.java.util.common.guava.MergeSequence)1 Sequence (io.druid.java.util.common.guava.Sequence)1 Query (io.druid.query.Query)1