Search in sources :

Example 31 with Routing

use of io.crate.metadata.Routing in project crate by crate.

the class RemoteCollectorTest method prepare.

@Before
public void prepare() {
    MockitoAnnotations.initMocks(this);
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 0, "remoteCollect", new Routing(Map.of("remoteNode", Map.of("dummyTable", IntArrayList.from(1)))), RowGranularity.DOC, Collections.singletonList(createReference("name", DataTypes.STRING)), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_BROADCAST);
    transportJobAction = mock(TransportJobAction.class);
    TasksService tasksService = new TasksService(clusterService, new JobsLogs(() -> true));
    numBroadcastCalls = new AtomicInteger(0);
    transportKillJobsNodeAction = new TransportKillJobsNodeAction(tasksService, clusterService, mock(TransportService.class)) {

        @Override
        public void broadcast(KillJobsRequest request, ActionListener<Long> listener) {
            numBroadcastCalls.incrementAndGet();
        }
    };
    consumer = new TestingRowConsumer();
    remoteCollector = new RemoteCollector(jobId, new SessionSettings("dummyUser", SearchPath.createSearchPathFrom("dummySchema")), "localNode", "remoteNode", transportJobAction, transportKillJobsNodeAction, Runnable::run, tasksService, RamAccounting.NO_ACCOUNTING, consumer, collectPhase);
}
Also used : TransportJobAction(io.crate.execution.jobs.transport.TransportJobAction) TransportKillJobsNodeAction(io.crate.execution.jobs.kill.TransportKillJobsNodeAction) Routing(io.crate.metadata.Routing) TasksService(io.crate.execution.jobs.TasksService) SessionSettings(io.crate.metadata.settings.SessionSettings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KillJobsRequest(io.crate.execution.jobs.kill.KillJobsRequest) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) UUID(java.util.UUID) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Before(org.junit.Before)

Example 32 with Routing

use of io.crate.metadata.Routing 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 33 with Routing

use of io.crate.metadata.Routing 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 34 with Routing

use of io.crate.metadata.Routing 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 35 with Routing

use of io.crate.metadata.Routing 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

Routing (io.crate.metadata.Routing)41 Test (org.junit.Test)23 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)18 Reference (io.crate.metadata.Reference)9 RelationName (io.crate.metadata.RelationName)8 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)8 ArrayList (java.util.ArrayList)7 Symbol (io.crate.expression.symbol.Symbol)6 ColumnIdent (io.crate.metadata.ColumnIdent)6 List (java.util.List)6 Map (java.util.Map)6 UUID (java.util.UUID)6 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)5 Row (io.crate.data.Row)5 EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)5 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)5 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)5 ImmutableList (com.google.common.collect.ImmutableList)4 WhereClause (io.crate.analyze.WhereClause)4 TableInfo (io.crate.metadata.table.TableInfo)4