Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/2.3' into 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
systay committed Jan 16, 2016
2 parents fd1743f + 7f31829 commit cadf7e9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,30 @@ class ShortestPathAcceptanceTest extends ExecutionEngineFunSuite with NewPlanner
result.toList should equal(List(Map("l" -> 16)))
}

test("shortest path and unwind should work together") {
val a1 = createLabeledNode("A")
val a2 = createLabeledNode("A")
val a3 = createLabeledNode("A")
val a4 = createLabeledNode("A")

relate(a1, a2, "T")
relate(a2, a3, "T")
relate(a3, a4, "T")

val result = executeWithAllPlanners(
"""
|MATCH p = (:A)-[:T*]-(:A)
|WITH p WHERE length(p) > 1
|UNWIND nodes(p)[1..-1] as n
|RETURN id(n) as n, count(*) as c""".stripMargin)

result.toList should equal(List(
Map("n" -> 5, "c" -> 4), Map("n" -> 6, "c" -> 4)
))

result.close()
}

def shortestPathModel(): Map[String, Node] = {
val nodes = Map[String, Node](
"source" -> createLabeledNode(Map("name" -> "x"), "X"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ case object unnestApply extends Rewriter {
CN : CreateNode
*/

private val instance: Rewriter = Rewriter.lift {
private val instance: Rewriter = bottomUp(Rewriter.lift {
// SR Ax R => R iff Arg0 introduces no arguments
case Apply(_: SingleRow, rhs) =>
rhs
Expand Down Expand Up @@ -86,7 +86,7 @@ case object unnestApply extends Rewriter {
// L Ax (CN R) => CN Ax (L R)
case apply@Apply(lhs, create@CreateNode(rhs, name, labels, props)) =>
CreateNode(Apply(lhs, rhs)(apply.solved), name, labels, props)(apply.solved)
}
})

override def apply(input: AnyRef) = bottomUp(instance).apply(input)
override def apply(input: AnyRef) = instance.apply(input)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package org.neo4j.cypher.internal.compiler.v3_0.planner
import org.neo4j.cypher.internal.compiler.v3_0._
import org.neo4j.cypher.internal.compiler.v3_0.ast.convert.plannerQuery.StatementConverters._
import org.neo4j.cypher.internal.compiler.v3_0.ast.rewriters.{normalizeReturnClauses, normalizeWithClauses}
import org.neo4j.cypher.internal.compiler.v3_0.helpers.Converge.iterateUntilConverged
import org.neo4j.cypher.internal.compiler.v3_0.pipes.EntityProducer
import org.neo4j.cypher.internal.compiler.v3_0.pipes.matching.{ExpanderStep, TraversalMatcher}
import org.neo4j.cypher.internal.compiler.v3_0.planner.logical.Metrics._
Expand All @@ -37,7 +36,7 @@ import org.neo4j.cypher.internal.compiler.v3_0.tracing.rewriters.RewriterStepSeq
import org.neo4j.cypher.internal.frontend.v3_0.ast._
import org.neo4j.cypher.internal.frontend.v3_0.parser.CypherParser
import org.neo4j.cypher.internal.frontend.v3_0.test_helpers.{CypherFunSuite, CypherTestSupport}
import org.neo4j.cypher.internal.frontend.v3_0.{Foldable, PropertyKeyId, SemanticTable, inSequence}
import org.neo4j.cypher.internal.frontend.v3_0.{Foldable, PropertyKeyId, SemanticTable, _}
import org.neo4j.graphdb.Node
import org.neo4j.helpers.collection.Visitable
import org.neo4j.kernel.api.constraints.UniquenessConstraint
Expand Down Expand Up @@ -174,10 +173,7 @@ trait LogicalPlanningTestSupport2 extends CypherTestSupport with AstConstruction
val context = LogicalPlanningContext(planContext, logicalPlanProducer, metrics, newTable, queryGraphSolver, QueryGraphSolverInput.empty)
val plannerQuery = unionQuery.queries.head
val resultPlan = planner.internalPlan(plannerQuery)(context)

val rewritten = iterateUntilConverged((p:LogicalPlan) => p.endoRewrite(unnestApply))(resultPlan)

SemanticPlan(rewritten, newTable)
SemanticPlan(resultPlan.endoRewrite(repeat(unnestApply)), newTable)
}
}

Expand Down

0 comments on commit cadf7e9

Please sign in to comment.