Search in sources :

Example 31 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase in project crate by crate.

the class BlobShardCollectorProviderTest method testReadIsolation.

@Test
public void testReadIsolation() throws Exception {
    execute("create blob table b1 clustered into 1 shards with (number_of_replicas = 0)");
    upload("b1", "foo");
    upload("b1", "bar");
    ensureGreen();
    assertBusy(new Initializer());
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Map.of()), RowGranularity.SHARD, List.of(), List.of(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_BROADCAST);
    // No read Isolation
    Iterable<Row> iterable = getBlobRows(collectPhase, false);
    assertThat(StreamSupport.stream(iterable.spliterator(), false).count(), is(2L));
    upload("b1", "newEntry1");
    assertThat(StreamSupport.stream(iterable.spliterator(), false).count(), is(3L));
    // Read isolation
    iterable = getBlobRows(collectPhase, true);
    assertThat(StreamSupport.stream(iterable.spliterator(), false).count(), is(3L));
    upload("b1", "newEntry2");
    assertThat(StreamSupport.stream(iterable.spliterator(), false).count(), is(3L));
}
Also used : Routing(io.crate.metadata.Routing) Row(io.crate.data.Row) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) SQLHttpIntegrationTest(io.crate.integrationtests.SQLHttpIntegrationTest) Test(org.junit.Test)

Example 32 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase in project crate by crate.

the class InsertFromSubQueryPlannerTest method test_insert_from_subquery_with_order_by_symbols_match_collect_symbols.

@Test
public void test_insert_from_subquery_with_order_by_symbols_match_collect_symbols() {
    // Ensures that order by symbols may also be rewritten to source lookup refs if collect symbols are rewritten
    Merge localMerge = e.plan("insert into target (id, name) " + "select id, name from users order by id, name");
    Collect collect = (Collect) localMerge.subPlan();
    RoutedCollectPhase collectPhase = (RoutedCollectPhase) collect.collectPhase();
    assertThat(collectPhase.orderBy().orderBySymbols(), is(collectPhase.toCollect()));
}
Also used : Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 33 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase in project crate by crate.

the class RoutedCollectPhaseTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    List<Symbol> toCollect = List.of(Literal.of(DataTypes.STRING, null));
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase cn = new RoutedCollectPhase(jobId, 0, "cn", new Routing(Map.of()), RowGranularity.DOC, toCollect, List.of(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_MODULO);
    BytesStreamOutput out = new BytesStreamOutput();
    cn.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    RoutedCollectPhase cn2 = new RoutedCollectPhase(in);
    assertThat(cn, equalTo(cn2));
    assertThat(cn.toCollect(), is(cn2.toCollect()));
    assertThat(cn.nodeIds(), is(cn2.nodeIds()));
    assertThat(cn.jobId(), is(cn2.jobId()));
    assertThat(cn.phaseId(), is(cn2.phaseId()));
    assertThat(cn.maxRowGranularity(), is(cn2.maxRowGranularity()));
    assertThat(cn.distributionInfo(), is(cn2.distributionInfo()));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) StreamInput(org.elasticsearch.common.io.stream.StreamInput) Routing(io.crate.metadata.Routing) UUID(java.util.UUID) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 34 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase in project crate by crate.

the class GroupByPlannerTest method testGroupByHavingNonDistributed.

@Test
public void testGroupByHavingNonDistributed() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    Merge merge = e.plan("select id from users group by id having id > 0");
    Collect collect = (Collect) merge.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.where(), isSQL("(doc.users.id > 0::bigint)"));
    assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class)));
    MergePhase localMergeNode = merge.mergePhase();
    assertThat(localMergeNode.projections(), empty());
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 35 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase in project crate by crate.

the class GroupByPlannerTest method testNoDistributedGroupByOnAllPrimaryKeys.

@Test
public void testNoDistributedGroupByOnAllPrimaryKeys() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addPartitionedTable("create table doc.empty_parted (" + "   id integer primary key," + "   date timestamp with time zone primary key" + ") clustered by (id) partitioned by (date)").build();
    Collect collect = e.plan("select count(*), id, date from empty_parted group by id, date limit 20");
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.projections().size(), is(3));
    assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
    assertThat(collectPhase.projections().get(0).requiredGranularity(), is(RowGranularity.SHARD));
    assertThat(collectPhase.projections().get(1), instanceOf(TopNProjection.class));
    assertThat(collectPhase.projections().get(2), instanceOf(EvalProjection.class));
}
Also used : Collect(io.crate.planner.node.dql.Collect) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) OrderedTopNProjection(io.crate.execution.dsl.projection.OrderedTopNProjection) TopNProjection(io.crate.execution.dsl.projection.TopNProjection) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Aggregations

RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)50 Test (org.junit.Test)39 Collect (io.crate.planner.node.dql.Collect)23 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)23 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)18 Routing (io.crate.metadata.Routing)18 MergePhase (io.crate.execution.dsl.phases.MergePhase)14 Merge (io.crate.planner.Merge)10 Symbol (io.crate.expression.symbol.Symbol)9 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)8 Reference (io.crate.metadata.Reference)8 Row (io.crate.data.Row)7 EvalProjection (io.crate.execution.dsl.projection.EvalProjection)7 ArrayList (java.util.ArrayList)6 Bucket (io.crate.data.Bucket)5 RelationName (io.crate.metadata.RelationName)5 UUID (java.util.UUID)4 ClusterService (org.elasticsearch.cluster.service.ClusterService)4 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)3 OrderBy (io.crate.analyze.OrderBy)3