Skip to content

Commit

Permalink
Move code of cypher compiled runtime to enterprise module
Browse files Browse the repository at this point in the history
  • Loading branch information
systay committed Feb 7, 2017
1 parent 84b5094 commit ec24ed3
Show file tree
Hide file tree
Showing 335 changed files with 5,109 additions and 2,425 deletions.

This file was deleted.

This file was deleted.

Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.cypher.internal.compiler.v3_2.codegen;
package org.neo4j.cypher.internal.compiler.v3_2;

import java.util.HashMap;
import java.util.Map;
Expand Down
@@ -0,0 +1,45 @@
package org.neo4j.cypher.internal.compiler.v3_2

import java.time.Clock

import org.neo4j.cypher.internal.compiler.v3_2.executionplan.{PlanFingerprint, PlanFingerprintReference}
import org.neo4j.cypher.internal.compiler.v3_2.helpers.RuntimeTypeConverter
import org.neo4j.cypher.internal.compiler.v3_2.phases.CompilerContext
import org.neo4j.cypher.internal.compiler.v3_2.planner.logical.{Metrics, MetricsFactory, QueryGraphSolver}
import org.neo4j.cypher.internal.compiler.v3_2.spi.PlanContext
import org.neo4j.cypher.internal.frontend.v3_2.InputPosition
import org.neo4j.cypher.internal.frontend.v3_2.phases.{CompilationPhaseTracer, InternalNotificationLogger, Monitors}

trait ContextCreator {
def create(tracer: CompilationPhaseTracer,
notificationLogger: InternalNotificationLogger,
planContext: PlanContext,
queryText: String,
offset: Option[InputPosition]): CompilerContext
}

class CommunityContextCreator(monitors: Monitors,
createFingerprintReference: Option[PlanFingerprint] => PlanFingerprintReference,
typeConverter: RuntimeTypeConverter,
metricsFactory: MetricsFactory,
queryGraphSolver: QueryGraphSolver,
config: CypherCompilerConfiguration,
updateStrategy: UpdateStrategy,
clock: Clock) extends ContextCreator {
override def create(tracer: CompilationPhaseTracer,
notificationLogger: InternalNotificationLogger,
planContext: PlanContext,
queryText: String,
offset: Option[InputPosition]): CompilerContext = {
val exceptionCreator = new SyntaxExceptionCreator(queryText, offset)

val metrics: Metrics = if (planContext == null)
null
else
metricsFactory.newMetrics(planContext.statistics)

new CompilerContext(exceptionCreator, tracer, notificationLogger, planContext, typeConverter, createFingerprintReference,
monitors, metrics, queryGraphSolver, config, updateStrategy, clock)
}

}
Expand Up @@ -21,8 +21,6 @@ package org.neo4j.cypher.internal.compiler.v3_2

import java.time.Clock

import org.neo4j.cypher.internal.compiler.v3_2.codegen.CodeGenConfiguration
import org.neo4j.cypher.internal.compiler.v3_2.codegen.spi.CodeStructure
import org.neo4j.cypher.internal.compiler.v3_2.executionplan._
import org.neo4j.cypher.internal.compiler.v3_2.executionplan.procs.ProcedureCallOrSchemaCommandPlanBuilder
import org.neo4j.cypher.internal.compiler.v3_2.helpers.RuntimeTypeConverter
Expand All @@ -36,6 +34,7 @@ import org.neo4j.cypher.internal.frontend.v3_2.InputPosition
import org.neo4j.cypher.internal.frontend.v3_2.ast.Statement
import org.neo4j.cypher.internal.frontend.v3_2.helpers.rewriting.RewriterStepSequencer
import org.neo4j.cypher.internal.frontend.v3_2.phases.{CompilationPhaseTracer, InternalNotificationLogger, Monitors}
import org.neo4j.cypher.internal.compiler.v3_2.phases.CompilerContext

case class CypherCompiler(createExecutionPlan: Transformer[CompilerContext],
astRewriter: ASTRewriter,
Expand All @@ -50,9 +49,8 @@ case class CypherCompiler(createExecutionPlan: Transformer[CompilerContext],
queryGraphSolver: QueryGraphSolver,
config: CypherCompilerConfiguration,
updateStrategy: UpdateStrategy,
codeGenConfiguration: CodeGenConfiguration,
clock: Clock,
structure: CodeStructure[GeneratedQuery]) {
contextCreation: ContextCreator) {

def planQuery(queryText: String,
context: PlanContext,
Expand All @@ -68,7 +66,7 @@ case class CypherCompiler(createExecutionPlan: Transformer[CompilerContext],
planContext: PlanContext,
offset: Option[InputPosition] = None,
tracer: CompilationPhaseTracer): (ExecutionPlan, Map[String, Any]) = {
val context = createContext(tracer, notificationLogger, planContext, input.queryText, input.startPosition, codeGenConfiguration)
val context = contextCreation.create(tracer, notificationLogger, planContext, input.queryText, input.startPosition)
val preparedCompilationState = prepareForCaching.transform(input, context)
val cache = provideCache(cacheAccessor, cacheMonitor, planContext)
val isStale = (plan: ExecutionPlan) => plan.isStale(planContext.txIdProvider, planContext.statistics)
Expand All @@ -88,7 +86,7 @@ case class CypherCompiler(createExecutionPlan: Transformer[CompilerContext],
val plannerName = PlannerName(plannerNameText)
val startState = CompilationState(queryText, offset, plannerName)
//TODO: these nulls are a short cut
val context = createContext(tracer, notificationLogger, planContext = null, rawQueryText, offset, codeGenConfiguration = null)
val context = contextCreation.create(tracer, notificationLogger, planContext = null, rawQueryText, offset)
CompilationPhases.parsing(sequencer).transform(startState, context)
}

Expand All @@ -102,7 +100,7 @@ case class CypherCompiler(createExecutionPlan: Transformer[CompilerContext],
ProcedureDeprecationWarnings andThen
ProcedureWarnings

val costBasedPlanning =
val costBasedPlanning: Transformer[CompilerContext] =
QueryPlanner().adds[LogicalPlan] andThen
PlanRewriter(sequencer) andThen
If(_.unionQuery.readOnly) (
Expand All @@ -127,26 +125,6 @@ case class CypherCompiler(createExecutionPlan: Transformer[CompilerContext],
new QueryCache(cacheAccessor, lRUCache)
})

private def createContext(tracer: CompilationPhaseTracer,
notificationLogger: InternalNotificationLogger,
planContext: PlanContext,
queryText: String,
offset: Option[InputPosition],
codeGenConfiguration: CodeGenConfiguration): CompilerContext = {
val exceptionCreator = new SyntaxExceptionCreator(queryText, offset)

val metrics: Metrics = if (planContext == null)
null
else
metricsFactory.newMetrics(planContext.statistics)

val context = CompilerContext(exceptionCreator, tracer, notificationLogger, planContext, typeConverter, createFingerprintReference,
monitors, metrics, queryGraphSolver, config, updateStrategy, clock)

context.
set(structure).
set(codeGenConfiguration)
}
}

case class CypherCompilerConfiguration(queryCacheSize: Int,
Expand Down
Expand Up @@ -21,10 +21,9 @@ package org.neo4j.cypher.internal.compiler.v3_2

import java.time.Clock

import org.neo4j.cypher.internal.compiler.v3_2.codegen.{CodeGenConfiguration, CodeGenMode}
import org.neo4j.cypher.internal.compiler.v3_2.codegen.spi.CodeStructure
import org.neo4j.cypher.internal.compiler.v3_2.executionplan._
import org.neo4j.cypher.internal.compiler.v3_2.helpers.RuntimeTypeConverter
import org.neo4j.cypher.internal.compiler.v3_2.phases.CompilerContext
import org.neo4j.cypher.internal.compiler.v3_2.planner.logical._
import org.neo4j.cypher.internal.compiler.v3_2.planner.logical.idp._
import org.neo4j.cypher.internal.frontend.v3_2.ast.Statement
Expand All @@ -36,19 +35,18 @@ object CypherCompilerFactory {

def costBasedCompiler(config: CypherCompilerConfiguration,
clock: Clock,
structure: CodeStructure[GeneratedQuery],
monitors: Monitors, logger: InfoLogger,
rewriterSequencer: (String) => RewriterStepSequencer,
plannerName: Option[CostBasedPlannerName],
runtimeName: Option[RuntimeName],
codeGenMode: Option[CodeGenMode],
updateStrategy: Option[UpdateStrategy],
typeConverter: RuntimeTypeConverter): CypherCompiler = {
typeConverter: RuntimeTypeConverter,
runtimeBuilder: RuntimeBuilder[CompilerContext]): CypherCompiler = {
val rewriter = new ASTRewriter(rewriterSequencer)
val metricsFactory = CachedMetricsFactory(SimpleMetricsFactory)

// Pick runtime based on input
val runtimePipeline = RuntimeBuilder.create(runtimeName, config.useErrorsOverWarnings)
val runtimePipeline = runtimeBuilder.create(runtimeName, config.useErrorsOverWarnings)

val planner = plannerName.getOrElse(CostBasedPlannerName.default)
val queryGraphSolver = createQueryGraphSolver(planner, monitors, config)
Expand All @@ -62,12 +60,12 @@ object CypherCompilerFactory {
val cacheMonitor = monitors.newMonitor[AstCacheMonitor](monitorTag)
val cache = new MonitoringCacheAccessor[Statement, ExecutionPlan](cacheMonitor)

val actualCodeGenMode = codeGenMode.getOrElse(CodeGenMode.default)
val codeGenConfiguration = CodeGenConfiguration(mode = actualCodeGenMode)
val contextCreator = new CommunityContextCreator(monitors, createFingerprintReference, typeConverter,
metricsFactory, queryGraphSolver, config, actualUpdateStrategy, clock)

CypherCompiler(runtimePipeline, rewriter, cache, planCacheFactory, cacheMonitor, monitors, rewriterSequencer,
createFingerprintReference, typeConverter, metricsFactory, queryGraphSolver, config, actualUpdateStrategy,
codeGenConfiguration, clock, structure)
createFingerprintReference, typeConverter, metricsFactory, queryGraphSolver, config, actualUpdateStrategy, clock,
contextCreator)
}

def createQueryGraphSolver(n: CostBasedPlannerName, monitors: Monitors, config: CypherCompilerConfiguration): QueryGraphSolver = n match {
Expand All @@ -86,7 +84,6 @@ object CypherCompilerFactory {
IDPQueryGraphSolver(singleComponentPlanner, cartesianProductsOrValueJoins, monitor)
}


private def logStalePlanRemovalMonitor(log: InfoLogger) = new AstCacheMonitor {
override def cacheDiscard(key: Statement, userKey: String) {
log.info(s"Discarded stale query from the query cache: $userKey")
Expand Down
Expand Up @@ -21,25 +21,16 @@ package org.neo4j.cypher.internal.compiler.v3_2

import org.neo4j.cypher.internal.compiler.v3_2.phases._
import org.neo4j.cypher.internal.frontend.v3_2.InvalidArgumentException
import org.neo4j.cypher.internal.frontend.v3_2.notification.RuntimeUnsupportedNotification

object RuntimeBuilder {
trait RuntimeBuilder[C <: CompilerContext] {
def create(runtimeName: Option[RuntimeName], useErrorsOverWarnings: Boolean): Transformer[C]
}

object CommunityRuntimeBuilder extends RuntimeBuilder[CompilerContext] {
def create(runtimeName: Option[RuntimeName], useErrorsOverWarnings: Boolean): Transformer[CompilerContext] = runtimeName match {
case None | Some(InterpretedRuntimeName) =>
BuildInterpretedExecutionPlan

case Some(CompiledRuntimeName) if useErrorsOverWarnings =>
BuildCompiledExecutionPlan andThen
If(_.maybeExecutionPlan.isEmpty)(
Do(_ => throw new InvalidArgumentException("The given query is not currently supported in the selected runtime"))
)

case Some(CompiledRuntimeName) =>
BuildCompiledExecutionPlan andThen
If(_.maybeExecutionPlan.isEmpty)(
Do { (c:CompilerContext) => c.notificationLogger.log(RuntimeUnsupportedNotification) } andThen
BuildInterpretedExecutionPlan
)

case Some(x) => throw new InvalidArgumentException(s"This version of Neo4j does not support requested runtime: $x")
}
}

0 comments on commit ec24ed3

Please sign in to comment.