Search in sources :

Example 21 with Routing

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

the class CollectTaskTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    localNodeId = "dummyLocalNodeId";
    collectPhase = Mockito.mock(RoutedCollectPhase.class);
    Routing routing = Mockito.mock(Routing.class);
    when(routing.containsShards(localNodeId)).thenReturn(true);
    when(collectPhase.routing()).thenReturn(routing);
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
    collectOperation = mock(MapSideDataCollectOperation.class);
    Mockito.doAnswer(new Answer<>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Runnable runnable = invocation.getArgument(0);
            runnable.run();
            return null;
        }
    }).when(collectOperation).launch(Mockito.any(), Mockito.anyString());
    consumer = new TestingRowConsumer();
    collectTask = new CollectTask(collectPhase, CoordinatorTxnCtx.systemTransactionContext(), collectOperation, RamAccounting.NO_ACCOUNTING, ramAccounting -> new OnHeapMemoryManager(ramAccounting::addBytes), consumer, mock(SharedShardContexts.class), Version.CURRENT, 4096);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) BatchIterator(io.crate.data.BatchIterator) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Routing(io.crate.metadata.Routing) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ESTestCase(org.elasticsearch.test.ESTestCase) Before(org.junit.Before) JobKilledException(io.crate.exceptions.JobKilledException) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) RamAccounting(io.crate.breaker.RamAccounting) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) Exceptions(io.crate.exceptions.Exceptions) Version(org.elasticsearch.Version) RowGranularity(io.crate.metadata.RowGranularity) Row(io.crate.data.Row) Matchers.is(org.hamcrest.Matchers.is) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) RefCountedItem(io.crate.common.collections.RefCountedItem) TestingRowConsumer(io.crate.testing.TestingRowConsumer) SentinelRow(io.crate.data.SentinelRow) Mockito.mock(org.mockito.Mockito.mock) IndexSearcher(org.apache.lucene.search.IndexSearcher) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) Routing(io.crate.metadata.Routing) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Before(org.junit.Before)

Example 22 with Routing

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

the class RoutingBuilderTest method testAllocateRouting.

@Test
public void testAllocateRouting() {
    RoutingBuilder routingBuilder = new RoutingBuilder(clusterService.state(), routingProvider);
    WhereClause whereClause = new WhereClause(new Function(EqOperator.SIGNATURE, List.of(tableInfo.getReference(new ColumnIdent("id")), Literal.of(2)), EqOperator.RETURN_TYPE));
    routingBuilder.newAllocations();
    routingBuilder.allocateRouting(tableInfo, WhereClause.MATCH_ALL, RoutingProvider.ShardSelection.ANY, null);
    routingBuilder.allocateRouting(tableInfo, whereClause, RoutingProvider.ShardSelection.ANY, null);
    // 2 routing allocations with different where clause must result in 2 allocated routings
    List<Routing> tableRoutings = routingBuilder.routingListByTableStack.pop().get(relationName);
    assertThat(tableRoutings.size(), is(2));
    // The routings are the same because the RoutingProvider enforces this - this test doesn't reflect that fact
    // currently because the used routing are stubbed via the TestingTableInfo
    Routing routing1 = tableRoutings.get(0);
    Routing routing2 = tableRoutings.get(1);
    assertThat(routing1, is(routing2));
}
Also used : Function(io.crate.expression.symbol.Function) ColumnIdent(io.crate.metadata.ColumnIdent) WhereClause(io.crate.analyze.WhereClause) Routing(io.crate.metadata.Routing) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 23 with Routing

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

the class RoutedCollectPhaseTest method testNormalizeNoop.

@Test
public void testNormalizeNoop() throws Exception {
    RoutedCollectPhase collect = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Collections.emptyMap()), RowGranularity.DOC, Collections.singletonList(Literal.of(10)), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_SAME_NODE);
    EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(nodeCtx);
    RoutedCollectPhase normalizedCollect = collect.normalize(normalizer, new CoordinatorTxnCtx(SessionContext.systemSessionContext()));
    assertThat(normalizedCollect, sameInstance(collect));
}
Also used : CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 24 with Routing

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

the class RoutedCollectPhaseTest method testNormalizeDoesNotRemoveOrderBy.

@Test
public void testNormalizeDoesNotRemoveOrderBy() throws Exception {
    Symbol toInt10 = CastFunctionResolver.generateCastFunction(Literal.of(10L), DataTypes.INTEGER);
    RoutedCollectPhase collect = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Collections.emptyMap()), RowGranularity.DOC, Collections.singletonList(toInt10), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_SAME_NODE);
    collect.orderBy(new OrderBy(Collections.singletonList(toInt10)));
    EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(nodeCtx);
    RoutedCollectPhase normalizedCollect = collect.normalize(normalizer, new CoordinatorTxnCtx(SessionContext.systemSessionContext()));
    assertThat(normalizedCollect.orderBy(), notNullValue());
}
Also used : OrderBy(io.crate.analyze.OrderBy) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Symbol(io.crate.expression.symbol.Symbol) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 25 with Routing

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

the class RoutedCollectPhaseTest method testNormalizePreservesNodePageSizeHint.

@Test
public void testNormalizePreservesNodePageSizeHint() throws Exception {
    Symbol toInt10 = CastFunctionResolver.generateCastFunction(Literal.of(10L), DataTypes.INTEGER);
    RoutedCollectPhase collect = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Collections.emptyMap()), RowGranularity.DOC, Collections.singletonList(toInt10), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_SAME_NODE);
    collect.nodePageSizeHint(10);
    EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(nodeCtx);
    RoutedCollectPhase normalizedCollect = collect.normalize(normalizer, new CoordinatorTxnCtx(SessionContext.systemSessionContext()));
    assertThat(normalizedCollect.nodePageSizeHint(), is(10));
}
Also used : CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Symbol(io.crate.expression.symbol.Symbol) 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