-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
PlanEventHorizon.scala
76 lines (64 loc) · 3.42 KB
/
PlanEventHorizon.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
/*
* 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.compiler.v3_4.planner.logical
import org.neo4j.cypher.internal.util.v3_4.InternalException
import org.neo4j.cypher.internal.compiler.v3_4.planner._
import org.neo4j.cypher.internal.compiler.v3_4.planner.logical.steps.{PatternExpressionSolver, aggregation, projection, sortSkipAndLimit}
import org.neo4j.cypher.internal.ir.v3_4._
import org.neo4j.cypher.internal.v3_4.logical.plans.LogicalPlan
/*
Planning event horizons means planning the WITH clauses between query patterns. Some of these clauses are inlined
away when going from a string query to a QueryGraph. The remaining WITHs are the ones containing ORDER BY/LIMIT,
aggregation and UNWIND.
*/
case object PlanEventHorizon
extends LogicalPlanningFunction2[PlannerQuery, LogicalPlan, LogicalPlan] {
override def apply(query: PlannerQuery, plan: LogicalPlan)(implicit context: LogicalPlanningContext): LogicalPlan = {
val selectedPlan = context.config.applySelections(plan, query.queryGraph)
val projectedPlan = query.horizon match {
case aggregatingProjection: AggregatingQueryProjection =>
val aggregationPlan = aggregation(selectedPlan, aggregatingProjection)
sortSkipAndLimit(aggregationPlan, query)
case queryProjection: RegularQueryProjection =>
val sortedAndLimited = sortSkipAndLimit(selectedPlan, query)
if (queryProjection.projections.isEmpty && query.tail.isEmpty)
context.logicalPlanProducer.planEmptyProjection(plan)
else
projection(sortedAndLimited, queryProjection.projections)
case queryProjection: DistinctQueryProjection =>
val projections = queryProjection.projections
val (inner, projectionsMap) = PatternExpressionSolver()(selectedPlan, projections)
val distinctPlan = context.logicalPlanProducer.planDistinct(inner, projectionsMap, projections)
sortSkipAndLimit(distinctPlan, query)
case UnwindProjection(variable, expression) =>
context.logicalPlanProducer.planUnwind(plan, variable, expression)
case ProcedureCallProjection(call) =>
context.logicalPlanProducer.planCallProcedure(plan, call)
case LoadCSVProjection(variableName, url, format, fieldTerminator) =>
context.logicalPlanProducer.planLoadCSV(plan, variableName, url, format, fieldTerminator)
case PassthroughAllHorizon() =>
context.logicalPlanProducer.planPassAll(plan)
case _ =>
throw new InternalException(s"Received QG with unknown horizon type: ${query.horizon}")
}
// We need to check if reads introduced in the horizon conflicts with future writes
Eagerness.horizonReadWriteEagerize(projectedPlan, query)
}
}