Search in sources :

Example 26 with RoutedCollectPhase

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

the class DocLevelCollectTest method testCollectWithPartitionedColumns.

@Test
public void testCollectWithPartitionedColumns() throws Throwable {
    RelationName relationName = new RelationName(Schemas.DOC_SCHEMA_NAME, PARTITIONED_TABLE_NAME);
    TableInfo tableInfo = schemas.getTableInfo(relationName);
    Routing routing = tableInfo.getRouting(clusterService().state(), new RoutingProvider(Randomness.get().nextInt(), Collections.emptyList()), WhereClause.MATCH_ALL, RoutingProvider.ShardSelection.ANY, SessionContext.systemSessionContext());
    RoutedCollectPhase collectNode = getCollectNode(Arrays.asList(tableInfo.getReference(new ColumnIdent("id")), tableInfo.getReference(new ColumnIdent("date"))), routing, WhereClause.MATCH_ALL);
    Bucket result = collect(collectNode);
    assertThat(result, containsInAnyOrder(isRow(1, 0L), isRow(2, 1L)));
}
Also used : RoutingProvider(io.crate.metadata.RoutingProvider) ColumnIdent(io.crate.metadata.ColumnIdent) Bucket(io.crate.data.Bucket) StreamBucket(io.crate.execution.engine.distribution.StreamBucket) RelationName(io.crate.metadata.RelationName) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Routing(io.crate.metadata.Routing) TableInfo(io.crate.metadata.table.TableInfo) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 27 with RoutedCollectPhase

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

the class DocLevelCollectTest method testCollectDocLevelWhereClause.

@Test
public void testCollectDocLevelWhereClause() throws Throwable {
    List<Symbol> arguments = Arrays.asList(testDocLevelReference, Literal.of(2));
    EqOperator op = (EqOperator) functions.get(null, EqOperator.NAME, arguments, SearchPath.pathWithPGCatalogAndDoc());
    List<Symbol> toCollect = Collections.singletonList(testDocLevelReference);
    WhereClause whereClause = new WhereClause(new Function(op.signature(), arguments, EqOperator.RETURN_TYPE));
    RoutedCollectPhase collectNode = getCollectNode(toCollect, whereClause);
    Bucket result = collect(collectNode);
    assertThat(result, contains(isRow(2)));
}
Also used : Function(io.crate.expression.symbol.Function) EqOperator(io.crate.expression.operator.EqOperator) Bucket(io.crate.data.Bucket) StreamBucket(io.crate.execution.engine.distribution.StreamBucket) Symbol(io.crate.expression.symbol.Symbol) WhereClause(io.crate.analyze.WhereClause) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 28 with RoutedCollectPhase

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

the class HandlerSideLevelCollectTest method testClusterLevel.

@Test
public void testClusterLevel() throws Exception {
    Schemas schemas = internalCluster().getInstance(Schemas.class);
    TableInfo tableInfo = schemas.getTableInfo(new RelationName("sys", "cluster"));
    Routing routing = tableInfo.getRouting(clusterService().state(), routingProvider, WhereClause.MATCH_ALL, RoutingProvider.ShardSelection.ANY, SessionContext.systemSessionContext());
    Reference clusterNameRef = new Reference(new ReferenceIdent(SysClusterTableInfo.IDENT, new ColumnIdent("name")), RowGranularity.CLUSTER, DataTypes.STRING, 1, null);
    RoutedCollectPhase collectNode = collectNode(routing, List.of(clusterNameRef), RowGranularity.CLUSTER);
    Bucket result = collect(collectNode);
    assertThat(result.size(), is(1));
    assertThat(((String) result.iterator().next().get(0)), Matchers.startsWith("SUITE-"));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) Reference(io.crate.metadata.Reference) RelationName(io.crate.metadata.RelationName) Routing(io.crate.metadata.Routing) TableInfo(io.crate.metadata.table.TableInfo) SysClusterTableInfo(io.crate.metadata.sys.SysClusterTableInfo) Schemas(io.crate.metadata.Schemas) ReferenceIdent(io.crate.metadata.ReferenceIdent) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 29 with RoutedCollectPhase

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

the class SystemCollectSourceTest method testOrderBySymbolsDoNotAppearTwiceInRows.

@Test
public void testOrderBySymbolsDoNotAppearTwiceInRows() throws Exception {
    SystemCollectSource systemCollectSource = internalCluster().getDataNodeInstance(SystemCollectSource.class);
    Reference shardId = new Reference(new ReferenceIdent(new RelationName("sys", "shards"), "id"), RowGranularity.SHARD, DataTypes.INTEGER, 0, null);
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Map.of()), RowGranularity.SHARD, Collections.singletonList(shardId), List.of(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_BROADCAST);
    collectPhase.orderBy(new OrderBy(Collections.singletonList(shardId), new boolean[] { false }, new boolean[] { false }));
    Iterable<? extends Row> rows = systemCollectSource.toRowsIterableTransformation(collectPhase, CoordinatorTxnCtx.systemTransactionContext(), unassignedShardRefResolver(), false).apply(Collections.singletonList(new UnassignedShard(1, "foo", mock(ClusterService.class), true, ShardRoutingState.UNASSIGNED)));
    Row next = rows.iterator().next();
    assertThat(next.numColumns(), is(1));
}
Also used : OrderBy(io.crate.analyze.OrderBy) ClusterService(org.elasticsearch.cluster.service.ClusterService) Reference(io.crate.metadata.Reference) RelationName(io.crate.metadata.RelationName) Routing(io.crate.metadata.Routing) Row(io.crate.data.Row) UnassignedShard(io.crate.metadata.shard.unassigned.UnassignedShard) ReferenceIdent(io.crate.metadata.ReferenceIdent) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 30 with RoutedCollectPhase

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

the class SystemCollectSourceTest method testReadIsolation.

@Test
public void testReadIsolation() throws Exception {
    SystemCollectSource systemCollectSource = internalCluster().getDataNodeInstance(SystemCollectSource.class);
    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
    List<String> noReadIsolationIterable = new ArrayList<>();
    noReadIsolationIterable.add("a");
    noReadIsolationIterable.add("b");
    CoordinatorTxnCtx txnCtx = CoordinatorTxnCtx.systemTransactionContext();
    Iterable<? extends Row> rows = systemCollectSource.toRowsIterableTransformation(collectPhase, txnCtx, unassignedShardRefResolver(), false).apply(noReadIsolationIterable);
    assertThat(StreamSupport.stream(rows.spliterator(), false).count(), is(2L));
    noReadIsolationIterable.add("c");
    assertThat(StreamSupport.stream(rows.spliterator(), false).count(), is(3L));
    // Read isolation
    List<String> readIsolationIterable = new ArrayList<>();
    readIsolationIterable.add("a");
    readIsolationIterable.add("b");
    rows = systemCollectSource.toRowsIterableTransformation(collectPhase, txnCtx, unassignedShardRefResolver(), true).apply(readIsolationIterable);
    assertThat(StreamSupport.stream(rows.spliterator(), false).count(), is(2L));
    readIsolationIterable.add("c");
    assertThat(StreamSupport.stream(rows.spliterator(), false).count(), is(2L));
}
Also used : CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) ArrayList(java.util.ArrayList) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

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