Search in sources :

Example 16 with CoordinatorTxnCtx

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

the class SQLIntegrationTestCase method plan.

public PlanForNode plan(String stmt) {
    String[] nodeNames = internalCluster().getNodeNames();
    String nodeName = nodeNames[randomIntBetween(1, nodeNames.length) - 1];
    Analyzer analyzer = internalCluster().getInstance(Analyzer.class, nodeName);
    Planner planner = internalCluster().getInstance(Planner.class, nodeName);
    NodeContext nodeCtx = internalCluster().getInstance(NodeContext.class, nodeName);
    SessionContext sessionContext = new SessionContext(User.CRATE_USER, sqlExecutor.getCurrentSchema());
    CoordinatorTxnCtx coordinatorTxnCtx = new CoordinatorTxnCtx(sessionContext);
    RoutingProvider routingProvider = new RoutingProvider(Randomness.get().nextInt(), planner.getAwarenessAttributes());
    PlannerContext plannerContext = new PlannerContext(planner.currentClusterState(), routingProvider, UUID.randomUUID(), coordinatorTxnCtx, nodeCtx, 0, null);
    Plan plan = planner.plan(analyzer.analyze(SqlParser.createStatement(stmt), coordinatorTxnCtx.sessionContext(), ParamTypeHints.EMPTY), plannerContext);
    return new PlanForNode(plan, nodeName, plannerContext);
}
Also used : RoutingProvider(io.crate.metadata.RoutingProvider) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) PlannerContext(io.crate.planner.PlannerContext) NodeContext(io.crate.metadata.NodeContext) SessionContext(io.crate.action.sql.SessionContext) Planner(io.crate.planner.Planner) Analyzer(io.crate.analyze.Analyzer) Plan(io.crate.planner.Plan)

Example 17 with CoordinatorTxnCtx

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

the class PlannerTest method testExecutionPhaseIdSequence.

@Test
public void testExecutionPhaseIdSequence() throws Exception {
    PlannerContext plannerContext = new PlannerContext(clusterService.state(), new RoutingProvider(Randomness.get().nextInt(), Collections.emptyList()), UUID.randomUUID(), new CoordinatorTxnCtx(SessionContext.systemSessionContext()), e.nodeCtx, 0, null);
    assertThat(plannerContext.nextExecutionPhaseId(), is(0));
    assertThat(plannerContext.nextExecutionPhaseId(), is(1));
}
Also used : RoutingProvider(io.crate.metadata.RoutingProvider) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 18 with CoordinatorTxnCtx

use of io.crate.metadata.CoordinatorTxnCtx 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 19 with CoordinatorTxnCtx

use of io.crate.metadata.CoordinatorTxnCtx 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 20 with CoordinatorTxnCtx

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

CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)44 Symbol (io.crate.expression.symbol.Symbol)27 NodeContext (io.crate.metadata.NodeContext)22 List (java.util.List)16 PlannerContext (io.crate.planner.PlannerContext)15 ArrayList (java.util.ArrayList)15 Map (java.util.Map)14 Lists2 (io.crate.common.collections.Lists2)13 Row (io.crate.data.Row)13 RelationName (io.crate.metadata.RelationName)13 Plan (io.crate.planner.Plan)13 SubQueryResults (io.crate.planner.operators.SubQueryResults)13 Function (java.util.function.Function)13 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)12 RowConsumer (io.crate.data.RowConsumer)12 DependencyCarrier (io.crate.planner.DependencyCarrier)12 HashMap (java.util.HashMap)12 Test (org.junit.Test)12 Row1 (io.crate.data.Row1)11 DocTableInfo (io.crate.metadata.doc.DocTableInfo)11