-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
helpers.scala
90 lines (80 loc) · 4.38 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
/*
* Copyright (c) 2002-2018 "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_2
import org.neo4j.cypher.InternalException
import org.neo4j.cypher.internal.compiler.v3_2.executionplan.{PlanFingerprint, StatsDivergenceCalculator, StatsDivergenceInverseDecayCalculator}
import org.neo4j.cypher.internal.compiler.v3_2.{CypherCompilerConfiguration => CypherCompilerConfiguration3_2}
import org.neo4j.cypher.internal.compiler.v3_3.CypherCompilerConfiguration
import org.neo4j.cypher.internal.frontend.v3_2.phases.CompilationPhaseTracer.{CompilationPhase => v3_2Phase, CompilationPhaseEvent => CompilationPhaseEvent3_2}
import org.neo4j.cypher.internal.frontend.v3_2.{InputPosition => InputPosition3_2}
import org.neo4j.cypher.internal.frontend.v3_3.phases.CompilationPhaseTracer.{CompilationPhase => v3_3Phase}
import org.neo4j.cypher.internal.frontend.v3_3.phases.{CompilationPhaseTracer, StatsDivergenceExponentialDecayCalculator}
import org.neo4j.cypher.internal.frontend.v3_3.{InputPosition, phases}
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_2(stats: phases.StatsDivergenceCalculator): StatsDivergenceCalculator = {
stats match {
case old: StatsDivergenceExponentialDecayCalculator =>
PlanFingerprint.divergenceCalculatorFor("exponential", old.initialThreshold, old.targetThreshold,
old.initialMillis, old.targetMillis)
case old: StatsDivergenceInverseDecayCalculator =>
PlanFingerprint.divergenceCalculatorFor("inverse", old.initialThreshold, old.targetThreshold,
old.initialMillis, old.targetMillis)
case _ =>
PlanFingerprint.divergenceNoDecayCalculator(stats.initialThreshold, stats.initialMillis)
}
}
def as3_2(config: CypherCompilerConfiguration): CypherCompilerConfiguration3_2 =
CypherCompilerConfiguration3_2(
config.queryCacheSize,
as3_2(config.statsDivergenceCalculator),
config.useErrorsOverWarnings,
config.idpMaxTableSize,
config.idpIterationDuration,
config.errorIfShortestPathFallbackUsedAtRuntime,
config.errorIfShortestPathHasCommonNodesAtRuntime,
config.legacyCsvQuoteEscaping,
config.nonIndexedLabelWarningThreshold,
config.planWithMinimumCardinalityEstimates)
def as3_2(tracer: CompilationPhaseTracer): org.neo4j.cypher.internal.frontend.v3_2.phases.CompilationPhaseTracer = {
new org.neo4j.cypher.internal.frontend.v3_2.phases.CompilationPhaseTracer {
override def beginPhase(phase: org.neo4j.cypher.internal.frontend.v3_2.phases.CompilationPhaseTracer.CompilationPhase): CompilationPhaseEvent3_2 = {
val wrappedPhase = phase match {
case v3_2Phase.AST_REWRITE => v3_3Phase.AST_REWRITE
case v3_2Phase.CODE_GENERATION => v3_3Phase.CODE_GENERATION
case v3_2Phase.LOGICAL_PLANNING => v3_3Phase.LOGICAL_PLANNING
case v3_2Phase.PARSING => v3_3Phase.PARSING
case v3_2Phase.PIPE_BUILDING => v3_3Phase.PIPE_BUILDING
case v3_2Phase.SEMANTIC_CHECK => v3_3Phase.SEMANTIC_CHECK
case v3_2Phase.DEPRECATION_WARNINGS => v3_3Phase.DEPRECATION_WARNINGS
case _ => throw new InternalException(s"Cannot handle $phase in 3.2")
}
val wrappedEvent = tracer.beginPhase(wrappedPhase)
new CompilationPhaseEvent3_2 {
override def close(): Unit = wrappedEvent.close()
}
}
}
}
def as3_2(pos: InputPosition): InputPosition3_2 = InputPosition3_2(pos.offset, pos.line, pos.column)
}