Search in sources :

Example 1 with Fragment

use of org.neo4j.fabric.planning.Fragment in project neo4j by neo4j.

the class FabricExecutor method run.

public StatementResult run(FabricTransaction fabricTransaction, String statement, MapValue parameters) {
    StatementLifecycle lifecycle = statementLifecycles.create(fabricTransaction.getTransactionInfo(), statement, parameters);
    lifecycle.startProcessing();
    fabricTransaction.setLastSubmittedStatement(lifecycle);
    try {
        String defaultGraphName = fabricTransaction.getTransactionInfo().getSessionDatabaseId().name();
        FabricPlanner.PlannerInstance plannerInstance = planner.instance(statement, parameters, defaultGraphName);
        UseEvaluation.Instance useEvaluator = useEvaluation.instance(statement);
        FabricPlan plan = plannerInstance.plan();
        Fragment query = plan.query();
        lifecycle.doneFabricProcessing(plan);
        AccessMode accessMode = fabricTransaction.getTransactionInfo().getAccessMode();
        RoutingContext routingContext = fabricTransaction.getTransactionInfo().getRoutingContext();
        if (plan.debugOptions().logPlan()) {
            log.debug(String.format("Fabric plan: %s", Fragment.pretty().asString(query)));
        }
        var statementResult = fabricTransaction.execute(ctx -> {
            FabricStatementExecution execution;
            if (plan.debugOptions().logRecords()) {
                execution = new FabricLoggingStatementExecution(plan, plannerInstance, useEvaluator, parameters, accessMode, routingContext, ctx, log, lifecycle, dataStreamConfig);
            } else {
                execution = new FabricStatementExecution(plan, plannerInstance, useEvaluator, parameters, accessMode, routingContext, ctx, lifecycle, dataStreamConfig);
            }
            return execution.run();
        });
        var resultWithErrorMapping = withErrorMapping(statementResult, FabricSecondaryException.class, FabricSecondaryException::getPrimaryException);
        return new FabricExecutionStatementResultImpl(resultWithErrorMapping, failure -> rollbackOnFailure(fabricTransaction, failure));
    } catch (RuntimeException e) {
        lifecycle.endFailure(e);
        rollbackOnFailure(fabricTransaction, e);
        throw e;
    }
}
Also used : UseEvaluation(org.neo4j.fabric.eval.UseEvaluation) FabricPlan(org.neo4j.fabric.planning.FabricPlan) Fragment(org.neo4j.fabric.planning.Fragment) RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) StatementLifecycle(org.neo4j.fabric.executor.FabricStatementLifecycles.StatementLifecycle) AccessMode(org.neo4j.bolt.runtime.AccessMode) FabricPlanner(org.neo4j.fabric.planning.FabricPlanner)

Aggregations

AccessMode (org.neo4j.bolt.runtime.AccessMode)1 RoutingContext (org.neo4j.bolt.v41.messaging.RoutingContext)1 UseEvaluation (org.neo4j.fabric.eval.UseEvaluation)1 StatementLifecycle (org.neo4j.fabric.executor.FabricStatementLifecycles.StatementLifecycle)1 FabricPlan (org.neo4j.fabric.planning.FabricPlan)1 FabricPlanner (org.neo4j.fabric.planning.FabricPlanner)1 Fragment (org.neo4j.fabric.planning.Fragment)1