use of org.apache.druid.query.groupby.GroupByQuery in project druid by druid-io.
the class DoubleMeanAggregationTest method testVectorAggretatorUsingGroupByQueryOnDoubleColumn.
@Test
@Parameters(method = "doVectorize")
public void testVectorAggretatorUsingGroupByQueryOnDoubleColumn(boolean doVectorize) throws Exception {
GroupByQuery query = new GroupByQuery.Builder().setDataSource("test").setGranularity(Granularities.ALL).setInterval("1970/2050").setAggregatorSpecs(new DoubleMeanAggregatorFactory("meanOnDouble", SimpleTestIndex.DOUBLE_COL)).setContext(Collections.singletonMap(QueryContexts.VECTORIZE_KEY, doVectorize)).build();
// do json serialization and deserialization of query to ensure there are no serde issues
ObjectMapper jsonMapper = groupByQueryTestHelper.getObjectMapper();
query = (GroupByQuery) jsonMapper.readValue(jsonMapper.writeValueAsString(query), Query.class);
Sequence<ResultRow> seq = groupByQueryTestHelper.runQueryOnSegmentsObjs(segments, query);
Row result = Iterables.getOnlyElement(seq.toList()).toMapBasedRow(query);
Assert.assertEquals(6.2d, result.getMetric("meanOnDouble").doubleValue(), 0.0001d);
}
use of org.apache.druid.query.groupby.GroupByQuery in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testGroupByOnArraysStringsasString.
@Test
public void testGroupByOnArraysStringsasString() {
final GroupByQuery query = (GroupByQuery) GroupByQuery.builder().setDataSource(ARRAY).setGranularity(Granularities.ALL).setInterval(Collections.singletonList(INTERVAL)).setDimensions(DefaultDimensionSpec.of("as")).build().withId(DUMMY_QUERY_ID);
testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of(new Object[] { ComparableStringArray.of("1.0", "2.0").toString() }, new Object[] { ComparableStringArray.of("2.0", "4.0").toString() }, new Object[] { ComparableStringArray.of("3.0", "6.0").toString() }, new Object[] { ComparableStringArray.of("4.0", "8.0").toString() }));
}
use of org.apache.druid.query.groupby.GroupByQuery in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testGroupByOnArraysDoublesAsString.
@Test
public void testGroupByOnArraysDoublesAsString() {
final GroupByQuery query = (GroupByQuery) GroupByQuery.builder().setDataSource(ARRAY).setGranularity(Granularities.ALL).setInterval(Collections.singletonList(INTERVAL)).setDimensions(DefaultDimensionSpec.of("ad")).build().withId(DUMMY_QUERY_ID);
testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of(new Object[] { new ComparableList(ImmutableList.of(1.0, 2.0)).toString() }, new Object[] { new ComparableList(ImmutableList.of(2.0, 4.0)).toString() }, new Object[] { new ComparableList(ImmutableList.of(3.0, 6.0)).toString() }, new Object[] { new ComparableList(ImmutableList.of(4.0, 8.0)).toString() }));
}
use of org.apache.druid.query.groupby.GroupByQuery in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testGroupByOnGroupByOnTable.
@Test
public void testGroupByOnGroupByOnTable() {
final GroupByQuery subquery = (GroupByQuery) GroupByQuery.builder().setDataSource(FOO).setGranularity(Granularities.ALL).setInterval(Collections.singletonList(INTERVAL)).setDimensions(DefaultDimensionSpec.of("s")).build().withId("queryId");
final GroupByQuery query = (GroupByQuery) GroupByQuery.builder().setDataSource(new QueryDataSource(subquery)).setGranularity(Granularities.ALL).setInterval(Intervals.ONLY_ETERNITY).setAggregatorSpecs(new CountAggregatorFactory("cnt")).build().withId(DUMMY_QUERY_ID);
testQuery(query, // GroupBy handles its own subqueries; only the inner one will go to the cluster. Also, it gets a subquery id
ImmutableList.of(ExpectedQuery.cluster(subquery.withSubQueryId("1.1"))), ImmutableList.of(new Object[] { 3L }));
Assert.assertEquals(1, scheduler.getTotalRun().get());
Assert.assertEquals(1, scheduler.getTotalPrioritizedAndLaned().get());
Assert.assertEquals(1, scheduler.getTotalAcquired().get());
Assert.assertEquals(1, scheduler.getTotalReleased().get());
}
use of org.apache.druid.query.groupby.GroupByQuery in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testGroupByOnArraysUnknownDoubles.
@Test
public void testGroupByOnArraysUnknownDoubles() {
final GroupByQuery query = (GroupByQuery) GroupByQuery.builder().setDataSource(ARRAY_UNKNOWN).setGranularity(Granularities.ALL).setInterval(Collections.singletonList(INTERVAL)).setDimensions(DefaultDimensionSpec.of("ad")).build().withId(DUMMY_QUERY_ID);
// 'unknown' is treated as ColumnType.STRING. this might not always be the case, so this is a test case of wacky
// behavior of sorts
testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of(new Object[] { "1.0" }, new Object[] { "2.0" }, new Object[] { "3.0" }, new Object[] { "4.0" }, new Object[] { "6.0" }, new Object[] { "8.0" }));
Assert.assertEquals(1, scheduler.getTotalRun().get());
Assert.assertEquals(1, scheduler.getTotalPrioritizedAndLaned().get());
Assert.assertEquals(1, scheduler.getTotalAcquired().get());
Assert.assertEquals(1, scheduler.getTotalReleased().get());
}
Aggregations