-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
helpers.scala
173 lines (151 loc) · 10.4 KB
/
helpers.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.compatibility.v3_3
import org.neo4j.cypher.CypherVersion.v3_3
import org.neo4j.cypher.InternalException
import org.neo4j.cypher.internal.compiler.v3_3.phases.{LogicalPlanState => LogicalPlanStateV3_3}
import org.neo4j.cypher.internal.compiler.v3_3.{CypherCompilerConfiguration => CypherCompilerConfiguration3_3, DPPlannerName => DPPlannerNameV3_3, IDPPlannerName => IDPPlannerNameV3_3, ProcedurePlannerName => ProcedurePlannerNameV3_3, UpdateStrategy => UpdateStrategyV3_3}
import org.neo4j.cypher.internal.compiler.v3_4.phases.LogicalPlanState
import org.neo4j.cypher.internal.compiler.v3_4.{CypherCompilerConfiguration, UpdateStrategy, defaultUpdateStrategy, eagerUpdateStrategy}
import org.neo4j.cypher.internal.compiler.{v3_4 => compilerV3_4}
import org.neo4j.cypher.internal.frontend.v3_3.ast.{Expression => ExpressionV3_3}
import org.neo4j.cypher.internal.frontend.v3_3.phases.CompilationPhaseTracer.{CompilationPhase => v3_3Phase}
import org.neo4j.cypher.internal.frontend.v3_3.phases.{CompilationPhaseTracer => CompilationPhaseTracer3_3}
import org.neo4j.cypher.internal.frontend.v3_3.{phases => phasesV3_3}
import org.neo4j.cypher.internal.frontend.v3_3.{InputPosition => InputPositionV3_3, PlannerName => PlannerNameV3_3, ast => astV3_3, notification => nfV3_3}
import org.neo4j.cypher.internal.frontend.v3_4.{PlannerName, ast => astV3_4, notification => nfV3_4}
import org.neo4j.cypher.internal.frontend.v3_4.phases.CompilationPhaseTracer
import org.neo4j.cypher.internal.frontend.v3_4.phases.CompilationPhaseTracer.{CompilationPhase => v3_4Phase}
import org.neo4j.cypher.internal.frontend.v3_4.{phases => phasesV3_4}
import org.neo4j.cypher.internal.ir.v3_3.{Cardinality => CardinalityV3_3}
import org.neo4j.cypher.internal.ir.{v3_3 => irV3_3, v3_4 => irV3_4}
import org.neo4j.cypher.internal.planner.v3_4.spi.{DPPlannerName, IDPPlannerName, PlannerNameWithVersion, ProcedurePlannerName}
import org.neo4j.cypher.internal.util.v3_4.attribution.Id
import org.neo4j.cypher.internal.util.v3_4.{Cardinality, InputPosition}
import org.neo4j.cypher.internal.v3_3.logical.plans.{LogicalPlanId => LogicalPlanIdV3_3}
import org.neo4j.kernel.impl.query.{QueryExecutionMonitor, TransactionalContext}
object helpers {
implicit def monitorFailure(t: Throwable)(implicit monitor: QueryExecutionMonitor, tc: TransactionalContext): Unit = {
monitor.endFailure(tc.executingQuery(), t)
}
def as3_3(config: CypherCompilerConfiguration): CypherCompilerConfiguration3_3 =
CypherCompilerConfiguration3_3(
config.queryCacheSize,
as3_3(config.statsDivergenceCalculator),
config.useErrorsOverWarnings,
config.idpMaxTableSize,
config.idpIterationDuration,
config.errorIfShortestPathFallbackUsedAtRuntime,
config.errorIfShortestPathHasCommonNodesAtRuntime,
config.legacyCsvQuoteEscaping,
config.nonIndexedLabelWarningThreshold)
/** This is awful but needed until 3_0 is updated no to send in the tracer here */
def as3_3(tracer: CompilationPhaseTracer): CompilationPhaseTracer3_3 = {
new CompilationPhaseTracer3_3 {
override def beginPhase(phase: CompilationPhaseTracer3_3.CompilationPhase) = {
val wrappedPhase = phase match {
case v3_3Phase.AST_REWRITE => v3_4Phase.AST_REWRITE
case v3_3Phase.CODE_GENERATION => v3_4Phase.CODE_GENERATION
case v3_3Phase.LOGICAL_PLANNING => v3_4Phase.LOGICAL_PLANNING
case v3_3Phase.PARSING => v3_4Phase.PARSING
case v3_3Phase.PIPE_BUILDING => v3_4Phase.PIPE_BUILDING
case v3_3Phase.SEMANTIC_CHECK => v3_4Phase.SEMANTIC_CHECK
case v3_3Phase.DEPRECATION_WARNINGS => v3_4Phase.DEPRECATION_WARNINGS
case _ => throw new InternalException(s"Cannot handle $phase in 3.3")
}
val wrappedEvent = tracer.beginPhase(wrappedPhase)
new CompilationPhaseTracer3_3.CompilationPhaseEvent {
override def close(): Unit = wrappedEvent.close()
}
}
}
}
def as3_3(calc: compilerV3_4.StatsDivergenceCalculator): phasesV3_3.StatsDivergenceCalculator = calc match {
case compilerV3_4.StatsDivergenceInverseDecayCalculator(initialThreshold, targetThreshold, initialMillis, targetMillis) =>
phasesV3_3.StatsDivergenceInverseDecayCalculator(initialThreshold, targetThreshold, initialMillis, targetMillis)
case compilerV3_4.StatsDivergenceExponentialDecayCalculator(initialThreshold, targetThreshold, initialMillis, targetMillis) =>
phasesV3_3.StatsDivergenceExponentialDecayCalculator(initialThreshold, targetThreshold, initialMillis, targetMillis)
case compilerV3_4.StatsDivergenceNoDecayCalculator(initialThreshold, initialMillis) =>
phasesV3_3.StatsDivergenceNoDecayCalculator(initialThreshold, initialMillis)
}
def as3_3(pos: InputPosition): InputPositionV3_3 = InputPositionV3_3(pos.offset, pos.line, pos.column)
def as3_4(pos: InputPositionV3_3): InputPosition = if(pos == null) null else InputPosition(pos.offset, pos.line, pos.column)
def as3_4(planId: LogicalPlanIdV3_3) : Id = Id(planId.underlying)
def as3_4(plannerName: PlannerNameV3_3) : PlannerName = plannerName match {
case IDPPlannerNameV3_3 => IDPPlannerName
case DPPlannerNameV3_3 => DPPlannerName
case ProcedurePlannerNameV3_3 => ProcedurePlannerName
}
def as3_4(updateStrategy: UpdateStrategyV3_3): UpdateStrategy = updateStrategy match {
case org.neo4j.cypher.internal.compiler.v3_3.eagerUpdateStrategy => eagerUpdateStrategy
case org.neo4j.cypher.internal.compiler.v3_3.defaultUpdateStrategy => defaultUpdateStrategy
}
def as3_4(periodicCommit: irV3_3.PeriodicCommit): irV3_4.PeriodicCommit = {
irV3_4.PeriodicCommit(periodicCommit.batchSize)
}
def as3_4(cardinality: CardinalityV3_3) : Cardinality = {
Cardinality(cardinality.amount)
}
def as3_4(statement: astV3_3.Statement) : astV3_4.Statement = StatementWrapper(statement)
def as3_4(notification: nfV3_3.InternalNotification): nfV3_4.InternalNotification = notification match {
case nfV3_3.DeprecatedStartNotification(position, alternativeQuery) => nfV3_4.DeprecatedStartNotification(as3_4(position), alternativeQuery)
case nfV3_3.CartesianProductNotification(position, isolatedVariables) => nfV3_4.CartesianProductNotification(as3_4(position), isolatedVariables)
case nfV3_3.LengthOnNonPathNotification(position) => nfV3_4.LengthOnNonPathNotification(as3_4(position))
case nfV3_3.PlannerUnsupportedNotification => nfV3_4.PlannerUnsupportedNotification
case nfV3_3.RuntimeUnsupportedNotification => nfV3_4.RuntimeUnsupportedNotification
case nfV3_3.IndexHintUnfulfillableNotification(label, propertyKeys) => nfV3_4.IndexHintUnfulfillableNotification(label, propertyKeys)
case nfV3_3.JoinHintUnfulfillableNotification(identified) => nfV3_4.JoinHintUnfulfillableNotification(identified)
case nfV3_3.JoinHintUnsupportedNotification(identified) => nfV3_4.JoinHintUnsupportedNotification(identified)
case nfV3_3.IndexLookupUnfulfillableNotification(labels) => nfV3_4.IndexLookupUnfulfillableNotification(labels)
case nfV3_3.EagerLoadCsvNotification => nfV3_4.EagerLoadCsvNotification
case nfV3_3.LargeLabelWithLoadCsvNotification => nfV3_4.LargeLabelWithLoadCsvNotification
case nfV3_3.MissingLabelNotification(position, label) => nfV3_4.MissingLabelNotification(as3_4(position), label)
case nfV3_3.MissingRelTypeNotification(position, relType) => nfV3_4.MissingRelTypeNotification(as3_4(position), relType)
case nfV3_3.MissingPropertyNameNotification(position, name) => nfV3_4.MissingPropertyNameNotification(as3_4(position), name)
case nfV3_3.UnboundedShortestPathNotification(position) => nfV3_4.UnboundedShortestPathNotification(as3_4(position))
case nfV3_3.ExhaustiveShortestPathForbiddenNotification(position) => nfV3_4.ExhaustiveShortestPathForbiddenNotification(as3_4(position))
case nfV3_3.DeprecatedFunctionNotification(position, oldName, newName) => nfV3_4.DeprecatedFunctionNotification(as3_4(position), oldName, newName)
case nfV3_3.DeprecatedProcedureNotification(position, oldName, newName) => nfV3_4.DeprecatedProcedureNotification(as3_4(position), oldName, newName)
case nfV3_3.ProcedureWarningNotification(position, procedure, warning) => nfV3_4.ProcedureWarningNotification(as3_4(position), procedure, warning)
case nfV3_3.DeprecatedFieldNotification(position, procedure, field) => nfV3_4.DeprecatedFieldNotification(as3_4(position), procedure, field)
case nfV3_3.DeprecatedVarLengthBindingNotification(position, variable) => nfV3_4.DeprecatedVarLengthBindingNotification(as3_4(position), variable)
case nfV3_3.DeprecatedRelTypeSeparatorNotification(position) => nfV3_4.DeprecatedRelTypeSeparatorNotification(as3_4(position))
case nfV3_3.DeprecatedPlannerNotification => nfV3_4.DeprecatedPlannerNotification
}
def as3_4(logicalPlan: LogicalPlanStateV3_3) : LogicalPlanState = {
val startPosition = logicalPlan.startPosition.map(as3_4)
// Wrap the planner name to correctly report version 3.3.
val plannerName = PlannerNameWithVersion(as3_4(logicalPlan.plannerName), v3_3.name)
def isImportant(expression: ExpressionV3_3) : Boolean = logicalPlan.maybeSemanticTable.exists(_.seen(expression))
val (plan3_4, expressionMap) = LogicalPlanConverter.convertLogicalPlan(logicalPlan.maybeLogicalPlan.get, isImportant)
val statement3_3 = logicalPlan.maybeStatement.get
LogicalPlanState(logicalPlan.queryText,
startPosition,
plannerName,
Some(as3_4(statement3_3)),
None,
logicalPlan.maybeExtractedParams,
logicalPlan.maybeSemanticTable.map(t => SemanticTableConverter.convertSemanticTable(t, expressionMap)),
None,
Some(plan3_4),
Some(logicalPlan.maybePeriodicCommit.flatten.map(x => as3_4(x))),
Set.empty)
}
}