use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class ExecutionPhasesTaskTest method testGroupByServer.
@Test
public void testGroupByServer() throws Exception {
Routing twoNodeRouting = new Routing(TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder().put("node1", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("t1", Arrays.asList(1, 2)).map()).put("node2", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("t1", Arrays.asList(3, 4)).map()).map());
UUID jobId = UUID.randomUUID();
RoutedCollectPhase c1 = new RoutedCollectPhase(jobId, 1, "c1", twoNodeRouting, RowGranularity.DOC, ImmutableList.of(), ImmutableList.of(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
MergePhase m1 = new MergePhase(jobId, 2, "merge1", 2, Collections.emptyList(), ImmutableList.of(), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
m1.executionNodes(Sets.newHashSet("node3", "node4"));
MergePhase m2 = new MergePhase(jobId, 3, "merge2", 2, Collections.emptyList(), ImmutableList.of(), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
m2.executionNodes(Sets.newHashSet("node1", "node3"));
String localNodeId = "node1";
NodeOperation n1 = NodeOperation.withDownstream(c1, m1, (byte) 0, localNodeId);
NodeOperation n2 = NodeOperation.withDownstream(m1, m2, (byte) 0, localNodeId);
NodeOperation n3 = NodeOperation.withDownstream(m2, mock(ExecutionPhase.class), (byte) 0, localNodeId);
Map<String, Collection<NodeOperation>> groupByServer = NodeOperationGrouper.groupByServer(ImmutableList.of(n1, n2, n3));
assertThat(groupByServer.containsKey("node1"), is(true));
assertThat(groupByServer.get("node1"), Matchers.containsInAnyOrder(n1, n3));
assertThat(groupByServer.containsKey("node2"), is(true));
assertThat(groupByServer.get("node2"), Matchers.containsInAnyOrder(n1));
assertThat(groupByServer.containsKey("node3"), is(true));
assertThat(groupByServer.get("node3"), Matchers.containsInAnyOrder(n2, n3));
assertThat(groupByServer.containsKey("node4"), is(true));
assertThat(groupByServer.get("node4"), Matchers.containsInAnyOrder(n2));
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class GroupByPlannerTest method testNonDistributedGroupByOnClusteredColumnSortedScalar.
@Test
public void testNonDistributedGroupByOnClusteredColumnSortedScalar() throws Exception {
Merge merge = e.plan("select count(*) + 1, id from users group by id order by count(*) + 1 limit 20");
Collect collect = (Collect) merge.subPlan();
RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
assertThat(collectPhase.projections().size(), is(2));
assertThat(collectPhase.projections().get(1), instanceOf(OrderedTopNProjection.class));
assertThat(((OrderedTopNProjection) collectPhase.projections().get(1)).orderBy().size(), is(1));
assertThat(collectPhase.projections().get(0).requiredGranularity(), is(RowGranularity.SHARD));
MergePhase mergePhase = merge.mergePhase();
assertThat(mergePhase.projections().size(), is(1));
assertThat(mergePhase.projections().get(0), instanceOf(TopNProjection.class));
PositionalOrderBy positionalOrderBy = mergePhase.orderByPositions();
assertThat(positionalOrderBy, notNullValue());
assertThat(positionalOrderBy.indices().length, is(1));
assertThat(positionalOrderBy.indices()[0], is(0));
assertThat(positionalOrderBy.reverseFlags()[0], is(false));
assertThat(positionalOrderBy.nullsFirst()[0], nullValue());
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class GroupByPlannerTest method testNonDistributedGroupByOnClusteredColumnSorted.
@Test
public void testNonDistributedGroupByOnClusteredColumnSorted() throws Exception {
Merge merge = e.plan("select count(*), id from users group by id order by 1 desc nulls last limit 20");
Collect collect = ((Collect) merge.subPlan());
RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
assertThat(collectPhase.projections().size(), is(2));
assertThat(collectPhase.projections().get(1), instanceOf(OrderedTopNProjection.class));
assertThat(((OrderedTopNProjection) collectPhase.projections().get(1)).orderBy().size(), is(1));
assertThat(collectPhase.projections().get(0).requiredGranularity(), is(RowGranularity.SHARD));
MergePhase mergePhase = merge.mergePhase();
assertThat(mergePhase.projections().size(), is(1));
assertThat(mergePhase.projections().get(0), instanceOf(TopNProjection.class));
PositionalOrderBy positionalOrderBy = mergePhase.orderByPositions();
assertThat(positionalOrderBy, notNullValue());
assertThat(positionalOrderBy.indices().length, is(1));
assertThat(positionalOrderBy.indices()[0], is(0));
assertThat(positionalOrderBy.reverseFlags()[0], is(true));
assertThat(positionalOrderBy.nullsFirst()[0], is(false));
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class GroupByPlannerTest method testNonDistributedGroupByAggregationsWrappedInScalar.
@Test
public void testNonDistributedGroupByAggregationsWrappedInScalar() throws Exception {
Merge planNode = e.plan("select (count(*) + 1), id from empty_parted group by id");
DistributedGroupBy distributedGroupBy = (DistributedGroupBy) planNode.subPlan();
RoutedCollectPhase collectPhase = distributedGroupBy.collectPhase();
assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class)));
assertThat(collectPhase.projections().size(), is(1));
assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
MergePhase mergePhase = planNode.mergePhase();
assertThat(mergePhase.projections().size(), is(0));
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class GroupByPlannerTest method testNonDistributedGroupByOnClusteredColumn.
@Test
public void testNonDistributedGroupByOnClusteredColumn() throws Exception {
Merge merge = e.plan("select count(*), id from users group by id limit 20");
Collect collect = ((Collect) merge.subPlan());
RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
assertThat(collectPhase.projections().size(), is(2));
assertThat(collectPhase.projections().get(1), instanceOf(TopNProjection.class));
assertThat(collectPhase.projections().get(0).requiredGranularity(), is(RowGranularity.SHARD));
MergePhase mergePhase = merge.mergePhase();
assertThat(mergePhase.projections().size(), is(1));
}
Aggregations