use of org.apache.druid.query.groupby.ResultRow in project druid by druid-io.
the class VectorizedVirtualColumnTest method testGroupBy.
private void testGroupBy(ColumnCapabilities capabilities, Map<String, Object> context, boolean canVectorize) {
GroupByQuery query = new GroupByQuery.Builder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setGranularity(Granularities.ALL).setVirtualColumns(new AlwaysTwoVectorizedVirtualColumn(ALWAYS_TWO, capabilities, canVectorize)).addDimension(new DefaultDimensionSpec(ALWAYS_TWO, ALWAYS_TWO, capabilities.toColumnType())).setAggregatorSpecs(new AlwaysTwoCounterAggregatorFactory(COUNT, ALWAYS_TWO)).setInterval("2000/2030").setContext(context).addOrderByColumn(ALWAYS_TWO).build();
List<ResultRow> rows = groupByTestHelper.runQueryOnSegmentsObjs(segments, query).toList();
List<ResultRow> expectedRows = Collections.singletonList(GroupByQueryRunnerTestHelper.createExpectedRow(query, "2000", COUNT, getCount(capabilities), ALWAYS_TWO, getTwo(capabilities)));
TestHelper.assertExpectedObjects(expectedRows, rows, "failed");
}
use of org.apache.druid.query.groupby.ResultRow in project druid by druid-io.
the class VectorizedVirtualColumnTest method testGroupByNoVirtual.
private void testGroupByNoVirtual(ColumnCapabilities capabilities, Map<String, Object> context) {
GroupByQuery query = new GroupByQuery.Builder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setGranularity(Granularities.ALL).setVirtualColumns().addDimension(new DefaultDimensionSpec("placement", "placement", capabilities.toColumnType())).setAggregatorSpecs(new CountAggregatorFactory(COUNT)).setInterval("2000/2030").setContext(context).build();
List<ResultRow> rows = groupByTestHelper.runQueryOnSegmentsObjs(segments, query).toList();
List<ResultRow> expectedRows = Collections.singletonList(GroupByQueryRunnerTestHelper.createExpectedRow(query, "2000", COUNT, 2418L, "placement", "preferred"));
TestHelper.assertExpectedObjects(expectedRows, rows, "failed");
}
use of org.apache.druid.query.groupby.ResultRow in project druid by druid-io.
the class TestHelper method assertObjects.
private static <T> void assertObjects(Iterable<T> expectedResults, Iterable<T> actualResults, String msg) {
Iterator resultsIter = actualResults.iterator();
Iterator resultsIter2 = actualResults.iterator();
Iterator expectedResultsIter = expectedResults.iterator();
int index = 0;
while (resultsIter.hasNext() && resultsIter2.hasNext() && expectedResultsIter.hasNext()) {
Object expectedNext = expectedResultsIter.next();
final Object next = resultsIter.next();
final Object next2 = resultsIter2.next();
String failMsg = msg + "-" + index++;
String failMsg2 = StringUtils.format("%s: Second iterator bad, multiple calls to iterator() should be safe", failMsg);
if (expectedNext instanceof ResultRow) {
// HACK! Special casing for groupBy
assertRow(failMsg, (ResultRow) expectedNext, (ResultRow) next);
assertRow(failMsg2, (ResultRow) expectedNext, (ResultRow) next2);
} else {
Assert.assertEquals(failMsg, expectedNext, next);
Assert.assertEquals(failMsg2, expectedNext, next2);
}
}
if (resultsIter.hasNext()) {
Assert.fail(StringUtils.format("%s: Expected resultsIter to be exhausted, next element was %s", msg, resultsIter.next()));
}
if (resultsIter2.hasNext()) {
Assert.fail(StringUtils.format("%s: Expected resultsIter2 to be exhausted, next element was %s", msg, resultsIter.next()));
}
if (expectedResultsIter.hasNext()) {
Assert.fail(StringUtils.format("%s: Expected expectedResultsIter to be exhausted, next element was %s", msg, expectedResultsIter.next()));
}
}
use of org.apache.druid.query.groupby.ResultRow in project druid by druid-io.
the class MultiValuedDimensionTest method testGroupByExpressionMultiMultiAutoAutoDupeIdentifier.
@Test
public void testGroupByExpressionMultiMultiAutoAutoDupeIdentifier() {
GroupByQuery query = GroupByQuery.builder().setDataSource("xx").setQuerySegmentSpec(new LegacySegmentSpec("1970/3000")).setGranularity(Granularities.ALL).setDimensions(new DefaultDimensionSpec("texpr", "texpr")).setVirtualColumns(new ExpressionVirtualColumn("texpr", "concat(tags, tags)", ColumnType.STRING, TestExprMacroTable.INSTANCE)).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("count", OrderByColumnSpec.Direction.DESCENDING)), 5)).setAggregatorSpecs(new CountAggregatorFactory("count")).setContext(context).build();
Sequence<ResultRow> result = helper.runQueryOnSegmentsObjs(ImmutableList.of(new QueryableIndexSegment(queryableIndex, SegmentId.dummy("sid1")), new IncrementalIndexSegment(incrementalIndex, SegmentId.dummy("sid2"))), query);
List<ResultRow> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970", "texpr", "t3t3", "count", 4L), GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970", "texpr", "t5t5", "count", 4L), GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970", "texpr", NullHandling.emptyToNullIfNeeded(""), "count", 2L), GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970", "texpr", "t1t1", "count", 2L), GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970", "texpr", "t2t2", "count", 2L));
TestHelper.assertExpectedObjects(expectedResults, result.toList(), "expr-multi-multi-auto-auto-self");
}
use of org.apache.druid.query.groupby.ResultRow in project druid by druid-io.
the class MultiValuedDimensionTest method testGroupByExpression.
@Test
public void testGroupByExpression() {
if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
expectedException.expect(RuntimeException.class);
expectedException.expectMessage("GroupBy v1 does not support dimension selectors with unknown cardinality.");
}
GroupByQuery query = GroupByQuery.builder().setDataSource("xx").setQuerySegmentSpec(new LegacySegmentSpec("1970/3000")).setGranularity(Granularities.ALL).setDimensions(new DefaultDimensionSpec("texpr", "texpr")).setVirtualColumns(new ExpressionVirtualColumn("texpr", "map(x -> concat(x, 'foo'), tags)", ColumnType.STRING, TestExprMacroTable.INSTANCE)).setAggregatorSpecs(new CountAggregatorFactory("count")).setContext(context).build();
Sequence<ResultRow> result = helper.runQueryOnSegmentsObjs(ImmutableList.of(new QueryableIndexSegment(queryableIndex, SegmentId.dummy("sid1")), new IncrementalIndexSegment(incrementalIndex, SegmentId.dummy("sid2"))), query);
List<ResultRow> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970", "texpr", NullHandling.sqlCompatible() ? "foo" : null, "count", 2L), GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970", "texpr", "t1foo", "count", 2L), GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970", "texpr", "t2foo", "count", 2L), GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970", "texpr", "t3foo", "count", 4L), GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970", "texpr", "t4foo", "count", 2L), GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970", "texpr", "t5foo", "count", 4L), GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970", "texpr", "t6foo", "count", 2L), GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970", "texpr", "t7foo", "count", 2L));
TestHelper.assertExpectedObjects(expectedResults, result.toList(), "expr");
}
Aggregations