Search in sources :

Example 56 with Collect

use of io.crate.planner.node.dql.Collect in project crate by crate.

the class InsertPlannerTest method testInsertFromSubQueryESGet.

@Test
public void testInsertFromSubQueryESGet() {
    Merge merge = e.plan("insert into users (date, id, name) (select date, id, name from users where id=1)");
    Collect queryAndFetch = (Collect) merge.subPlan();
    PKLookupPhase collectPhase = ((PKLookupPhase) queryAndFetch.collectPhase());
    assertThat(collectPhase.projections().size(), is(1));
    assertThat(collectPhase.projections().get(0), instanceOf(ColumnIndexWriterProjection.class));
    ColumnIndexWriterProjection projection = (ColumnIndexWriterProjection) collectPhase.projections().get(0);
    assertThat(projection.columnReferencesExclPartition().size(), is(3));
    assertThat(projection.columnReferencesExclPartition().get(0).column().fqn(), is("date"));
    assertThat(projection.columnReferencesExclPartition().get(1).column().fqn(), is("id"));
    assertThat(projection.columnReferencesExclPartition().get(2).column().fqn(), is("name"));
    assertThat(((InputColumn) projection.ids().get(0)).index(), is(1));
    assertThat(((InputColumn) projection.clusteredBy()).index(), is(1));
    assertThat(projection.partitionedBySymbols().isEmpty(), is(true));
}
Also used : PKLookupPhase(io.crate.execution.dsl.phases.PKLookupPhase) Collect(io.crate.planner.node.dql.Collect) ColumnIndexWriterProjection(io.crate.execution.dsl.projection.ColumnIndexWriterProjection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 57 with Collect

use of io.crate.planner.node.dql.Collect in project crate by crate.

the class InsertPlannerTest method test_insert_from_group_by_uses_doc_values.

@Test
public void test_insert_from_group_by_uses_doc_values() throws Exception {
    Merge merge = e.plan("insert into users (id) (select id from users group by 1)");
    Collect collect = (Collect) merge.subPlan();
    assertThat(collect.collectPhase().toCollect(), contains(SymbolMatchers.isReference("id")));
}
Also used : Collect(io.crate.planner.node.dql.Collect) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 58 with Collect

use of io.crate.planner.node.dql.Collect in project crate by crate.

the class InsertPlannerTest method testInsertFromSubQueryReduceOnCollectorGroupBy.

@Test
public void testInsertFromSubQueryReduceOnCollectorGroupBy() {
    Merge merge = e.plan("insert into users (id, name) (select id, arbitrary(name) from users group by id)");
    Collect collect = (Collect) merge.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
    ColumnIndexWriterProjection columnIndexWriterProjection = (ColumnIndexWriterProjection) collectPhase.projections().get(1);
    assertThat(columnIndexWriterProjection.columnReferencesExclPartition(), contains(isReference("id"), isReference("name")));
    MergePhase mergePhase = merge.mergePhase();
    assertThat(mergePhase.projections(), contains(instanceOf(MergeCountProjection.class)));
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) Collect(io.crate.planner.node.dql.Collect) ColumnIndexWriterProjection(io.crate.execution.dsl.projection.ColumnIndexWriterProjection) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 59 with Collect

use of io.crate.planner.node.dql.Collect in project crate by crate.

the class InsertPlannerTest method testInsertFromSubQueryWithOffsetDoesTableWriteOnCollect.

@Test
public void testInsertFromSubQueryWithOffsetDoesTableWriteOnCollect() {
    QueryThenFetch qtf = e.plan("insert into users (id, name) (select id, name from users offset 10)");
    Merge merge = (Merge) qtf.subPlan();
    // We can ignore the offset since SQL semantics don't promise a deterministic order without explicit order by clause
    Collect collect = (Collect) merge.subPlan();
    assertThat(collect.collectPhase().projections(), Matchers.empty());
    assertThat(merge.mergePhase().projections(), contains(instanceOf(FetchProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
}
Also used : QueryThenFetch(io.crate.planner.node.dql.QueryThenFetch) Collect(io.crate.planner.node.dql.Collect) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 60 with Collect

use of io.crate.planner.node.dql.Collect in project crate by crate.

the class InsertPlannerTest method test_insert_from_sub_query_with_sys_tables_has_no_doc_lookup.

@Test
public void test_insert_from_sub_query_with_sys_tables_has_no_doc_lookup() {
    Collect collect = e.plan("insert into users (id, name) (select oid, typname from pg_catalog.pg_type)");
    assertThat(collect.collectPhase().toCollect(), contains(isReference("oid"), isReference("typname")));
}
Also used : Collect(io.crate.planner.node.dql.Collect) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

Collect (io.crate.planner.node.dql.Collect)66 Test (org.junit.Test)57 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)55 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)31 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)27 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)18 EvalProjection (io.crate.execution.dsl.projection.EvalProjection)16 Merge (io.crate.planner.Merge)16 MergePhase (io.crate.execution.dsl.phases.MergePhase)14 Projection (io.crate.execution.dsl.projection.Projection)12 Reference (io.crate.metadata.Reference)11 FilterProjection (io.crate.execution.dsl.projection.FilterProjection)10 TopNProjection (io.crate.execution.dsl.projection.TopNProjection)10 OrderedTopNProjection (io.crate.execution.dsl.projection.OrderedTopNProjection)9 CollectPhase (io.crate.execution.dsl.phases.CollectPhase)8 Symbol (io.crate.expression.symbol.Symbol)8 AggregationProjection (io.crate.execution.dsl.projection.AggregationProjection)6 QueryThenFetch (io.crate.planner.node.dql.QueryThenFetch)6 ColumnIndexWriterProjection (io.crate.execution.dsl.projection.ColumnIndexWriterProjection)5 InputColumn (io.crate.expression.symbol.InputColumn)5