Search in sources :

Example 1 with MergePhase

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));
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Routing(io.crate.metadata.Routing) ImmutableList(com.google.common.collect.ImmutableList) NodeOperation(io.crate.operation.NodeOperation) ExecutionPhase(io.crate.planner.node.ExecutionPhase) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test)

Example 2 with MergePhase

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());
}
Also used : PositionalOrderBy(io.crate.planner.PositionalOrderBy) MergePhase(io.crate.planner.node.dql.MergePhase) Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with MergePhase

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));
}
Also used : PositionalOrderBy(io.crate.planner.PositionalOrderBy) MergePhase(io.crate.planner.node.dql.MergePhase) Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 4 with MergePhase

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));
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Merge(io.crate.planner.Merge) DistributedGroupBy(io.crate.planner.node.dql.DistributedGroupBy) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 5 with MergePhase

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));
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

MergePhase (io.crate.planner.node.dql.MergePhase)30 Test (org.junit.Test)27 CrateUnitTest (io.crate.test.integration.CrateUnitTest)26 Merge (io.crate.planner.Merge)15 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)15 DistributedGroupBy (io.crate.planner.node.dql.DistributedGroupBy)13 Collect (io.crate.planner.node.dql.Collect)9 Reference (io.crate.metadata.Reference)3 Projection (io.crate.planner.projection.Projection)3 ImmutableList (com.google.common.collect.ImmutableList)2 InputColumn (io.crate.analyze.symbol.InputColumn)2 Symbol (io.crate.analyze.symbol.Symbol)2 Routing (io.crate.metadata.Routing)2 NodeOperation (io.crate.operation.NodeOperation)2 CountAggregation (io.crate.operation.aggregation.impl.CountAggregation)2 PositionalOrderBy (io.crate.planner.PositionalOrderBy)2 Aggregation (io.crate.analyze.symbol.Aggregation)1 FunctionIdent (io.crate.metadata.FunctionIdent)1 FunctionInfo (io.crate.metadata.FunctionInfo)1 ExecutionPhase (io.crate.planner.node.ExecutionPhase)1