use of org.apache.druid.query.QueryDataSource in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testJoinOnGroupByOnTable.
@Test
public void testJoinOnGroupByOnTable() {
final GroupByQuery subquery = GroupByQuery.builder().setDataSource(FOO).setGranularity(Granularities.ALL).setInterval(Collections.singletonList(INTERVAL)).setDimensions(DefaultDimensionSpec.of("s")).setDimFilter(new SelectorDimFilter("s", "y", null)).build();
final GroupByQuery query = (GroupByQuery) GroupByQuery.builder().setDataSource(JoinDataSource.create(new TableDataSource(FOO), new QueryDataSource(subquery), "j.", "\"j.s\" == \"s\"", JoinType.INNER, null, ExprMacroTable.nil())).setGranularity(Granularities.ALL).setInterval(Intervals.ONLY_ETERNITY).setDimensions(DefaultDimensionSpec.of("s"), DefaultDimensionSpec.of("j.s")).setAggregatorSpecs(new CountAggregatorFactory("cnt")).build().withId(DUMMY_QUERY_ID);
testQuery(query, ImmutableList.of(ExpectedQuery.cluster(subquery.withId(DUMMY_QUERY_ID).withSubQueryId("2.1")), ExpectedQuery.cluster(query.withDataSource(query.getDataSource().withChildren(ImmutableList.of(query.getDataSource().getChildren().get(0), InlineDataSource.fromIterable(ImmutableList.of(new Object[] { "y" }), RowSignature.builder().add("s", ColumnType.STRING).build())))))), ImmutableList.of(new Object[] { "y", "y", 1L }));
// note: this should really be 1, but in the interim queries that are composed of multiple queries count each
// invocation of either the cluster or local walker in ClientQuerySegmentWalker
Assert.assertEquals(2, scheduler.getTotalRun().get());
Assert.assertEquals(2, scheduler.getTotalPrioritizedAndLaned().get());
Assert.assertEquals(2, scheduler.getTotalAcquired().get());
Assert.assertEquals(2, scheduler.getTotalReleased().get());
}
use of org.apache.druid.query.QueryDataSource in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testTimeseriesOnGroupByOnTableErrorTooManyRows.
@Test
public void testTimeseriesOnGroupByOnTableErrorTooManyRows() {
initWalker(ImmutableMap.of("maxSubqueryRows", "2"));
final GroupByQuery subquery = GroupByQuery.builder().setDataSource(FOO).setGranularity(Granularities.ALL).setInterval(Collections.singletonList(INTERVAL)).setDimensions(DefaultDimensionSpec.of("s")).build();
final TimeseriesQuery query = (TimeseriesQuery) Druids.newTimeseriesQueryBuilder().dataSource(new QueryDataSource(subquery)).granularity(Granularities.ALL).intervals(Intervals.ONLY_ETERNITY).aggregators(new CountAggregatorFactory("cnt")).build().withId(DUMMY_QUERY_ID);
expectedException.expect(ResourceLimitExceededException.class);
expectedException.expectMessage("Subquery generated results beyond maximum[2]");
testQuery(query, ImmutableList.of(), ImmutableList.of());
}
use of org.apache.druid.query.QueryDataSource in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testGroupByOnScanMultiValue.
@Test
public void testGroupByOnScanMultiValue() {
ScanQuery subquery = new Druids.ScanQueryBuilder().dataSource(MULTI).columns("s", "n").intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.ETERNITY))).legacy(false).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).build();
final GroupByQuery query = (GroupByQuery) GroupByQuery.builder().setDataSource(new QueryDataSource(subquery)).setGranularity(Granularities.ALL).setInterval(Intervals.ONLY_ETERNITY).setDimensions(DefaultDimensionSpec.of("s")).setAggregatorSpecs(new LongSumAggregatorFactory("sum_n", "n")).build().withId(DUMMY_QUERY_ID);
testQuery(query, // GroupBy handles its own subqueries; only the inner one will go to the cluster.
ImmutableList.of(ExpectedQuery.cluster(subquery.withId(DUMMY_QUERY_ID).withSubQueryId("1.1")), ExpectedQuery.local(query.withDataSource(InlineDataSource.fromIterable(ImmutableList.of(new Object[] { ImmutableList.of("a", "b"), 1 }, new Object[] { ImmutableList.of("a", "c"), 2 }, new Object[] { ImmutableList.of("b"), 3 }, new Object[] { ImmutableList.of("c"), 4 }), RowSignature.builder().add("s", null).add("n", null).build())))), ImmutableList.of(new Object[] { "a", 3L }, new Object[] { "b", 4L }, new Object[] { "c", 6L }));
Assert.assertEquals(2, scheduler.getTotalRun().get());
Assert.assertEquals(1, scheduler.getTotalPrioritizedAndLaned().get());
Assert.assertEquals(2, scheduler.getTotalAcquired().get());
Assert.assertEquals(2, scheduler.getTotalReleased().get());
}
use of org.apache.druid.query.QueryDataSource in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testJoinOnGroupByOnUnionOfTables.
@Test
public void testJoinOnGroupByOnUnionOfTables() {
final UnionDataSource unionDataSource = new UnionDataSource(ImmutableList.of(new TableDataSource(FOO), new TableDataSource(BAR)));
final GroupByQuery subquery = GroupByQuery.builder().setDataSource(unionDataSource).setGranularity(Granularities.ALL).setInterval(Collections.singletonList(INTERVAL)).setDimensions(DefaultDimensionSpec.of("s")).setDimFilter(new SelectorDimFilter("s", "y", null)).build();
final GroupByQuery query = (GroupByQuery) GroupByQuery.builder().setDataSource(JoinDataSource.create(unionDataSource, new QueryDataSource(subquery), "j.", "\"j.s\" == \"s\"", JoinType.INNER, null, ExprMacroTable.nil())).setGranularity(Granularities.ALL).setInterval(Intervals.ONLY_ETERNITY).setDimensions(DefaultDimensionSpec.of("s"), DefaultDimensionSpec.of("j.s")).setAggregatorSpecs(new CountAggregatorFactory("cnt")).build().withId(DUMMY_QUERY_ID);
testQuery(query, ImmutableList.of(ExpectedQuery.cluster(subquery.withDataSource(subquery.getDataSource().getChildren().get(0)).withId(DUMMY_QUERY_ID).withSubQueryId("2.1.foo.1")), ExpectedQuery.cluster(subquery.withDataSource(subquery.getDataSource().getChildren().get(1)).withId(DUMMY_QUERY_ID).withSubQueryId("2.1.bar.2")), ExpectedQuery.cluster(query.withDataSource(query.getDataSource().withChildren(ImmutableList.of(unionDataSource.getChildren().get(0), InlineDataSource.fromIterable(ImmutableList.of(new Object[] { "y" }), RowSignature.builder().add("s", ColumnType.STRING).build())))).withSubQueryId("foo.1")), ExpectedQuery.cluster(query.withDataSource(query.getDataSource().withChildren(ImmutableList.of(unionDataSource.getChildren().get(1), InlineDataSource.fromIterable(ImmutableList.of(new Object[] { "y" }), RowSignature.builder().add("s", ColumnType.STRING).build())))).withSubQueryId("bar.2"))), ImmutableList.of(new Object[] { "y", "y", 1L }));
// note: this should really be 1, but in the interim queries that are composed of multiple queries count each
// invocation of either the cluster or local walker in ClientQuerySegmentWalker
Assert.assertEquals(4, scheduler.getTotalRun().get());
Assert.assertEquals(4, scheduler.getTotalPrioritizedAndLaned().get());
Assert.assertEquals(4, scheduler.getTotalAcquired().get());
Assert.assertEquals(4, scheduler.getTotalReleased().get());
}
use of org.apache.druid.query.QueryDataSource in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testTopNScanMultiValue.
@Test
public void testTopNScanMultiValue() {
ScanQuery subquery = new Druids.ScanQueryBuilder().dataSource(MULTI).columns("s", "n").intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.ETERNITY))).legacy(false).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).build();
final TopNQuery query = (TopNQuery) new TopNQueryBuilder().dataSource(new QueryDataSource(subquery)).granularity(Granularities.ALL).intervals(Intervals.ONLY_ETERNITY).dimension(DefaultDimensionSpec.of("s")).metric("sum_n").threshold(100).aggregators(new LongSumAggregatorFactory("sum_n", "n")).build().withId(DUMMY_QUERY_ID);
testQuery(query, // GroupBy handles its own subqueries; only the inner one will go to the cluster.
ImmutableList.of(ExpectedQuery.cluster(subquery.withId(DUMMY_QUERY_ID).withSubQueryId("1.1")), ExpectedQuery.local(query.withDataSource(InlineDataSource.fromIterable(ImmutableList.of(new Object[] { ImmutableList.of("a", "b"), 1 }, new Object[] { ImmutableList.of("a", "c"), 2 }, new Object[] { ImmutableList.of("b"), 3 }, new Object[] { ImmutableList.of("c"), 4 }), RowSignature.builder().add("s", null).add("n", null).build())))), ImmutableList.of(new Object[] { Intervals.ETERNITY.getStartMillis(), "c", 6L }, new Object[] { Intervals.ETERNITY.getStartMillis(), "b", 4L }, new Object[] { Intervals.ETERNITY.getStartMillis(), "a", 3L }));
Assert.assertEquals(2, scheduler.getTotalRun().get());
Assert.assertEquals(1, scheduler.getTotalPrioritizedAndLaned().get());
Assert.assertEquals(2, scheduler.getTotalAcquired().get());
Assert.assertEquals(2, scheduler.getTotalReleased().get());
}
Aggregations