Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed shortestPath planning when preceded by unwind #8699

Merged
merged 2 commits into from Jan 27, 2017

Conversation

craigtaverner
Copy link
Contributor

No description provided.

Copy link
Contributor

@Mats-SX Mats-SX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code change looks good, would like to see the test code cleaned up a bit.

setupModel()
val result = executeUsingCostPlannerOnly(
"""
|//same idea but iterating over two collections of nodes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same idea as what? The below test? I find this in-query comment a bit redundant wrt the test name.

|match pathx = allShortestPaths((charlesThompson)-[*1..5]-(joeySantiago))
|where none (n IN nodes(pathx) where id(n) = id(kimDeal))
|with nodes(pathx) as nodes
|return nodes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a pretty complex query, I think it'd aid readability to format it more in line with Cypher code style.

""".stripMargin)
val results = result.columnAs("nodes").toList
println(results)
println(result.executionPlanDescription())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove printlns.

val results = result.columnAs("nodes").toList
println(results)
println(result.executionPlanDescription())
val ids = results(0).asInstanceOf[Seq[_]].map(n => n.asInstanceOf[Node].getId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are asserting on the ids only, isn't it easier to adapt the query to return only ids, instead of this mouthful?

E.g:

...
RETURN [n IN nodes | id(n)] AS ids

and then

result.toList should equal List(Map("ids" -> List(0, 4, 3, 2)))

That also makes sure that there isn't a second row returned (which is overlooked by only asserting on results(0)).

}

test("shortestPath with complex LHS should be planned with exhaustive fallback and include predicate") {
System.setProperty("pickBestPlan.VERBOSE","true")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

|match pathx = shortestPath((charlesThompson)-[*1..5]-(joeySantiago))
|where none (n IN nodes(pathx) where id(n) = id(kimDeal))
|unwind nodes(pathx) as nodes
|return nodes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I please request Cypher styling of this one too? :)

""".stripMargin)
val results = result.columnAs("nodes").toList
println(results)
println(result.executionPlanDescription())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

val results = result.columnAs("nodes").toList
println(results)
println(result.executionPlanDescription())
assertThat(results.length, equalTo(4))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a pretty vague result assertion; why not assert on the exact result contents?

|merge (p4:Pixie {fname:'David'})
|merge (p5:Pixie {fname:'Paz'})
|merge (p1)-[:KNOWS]->(p2)-[:KNOWS]->(p3)-[:KNOWS]->(p4)-[:KNOWS]->(p5)-[:KNOWS]->(p1)
|return p1,p2,p3,p4,p5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it doesn't matter a lot, but these could be CREATE instead, and RETURN (and the comment) may be omitted.

|UNWIND joeyS AS joeySantiago
|MATCH pathx = allShortestPaths((charlesThompson)-[*1..5]-(joeySantiago))
|WHERE none (n IN nodes(pathx) WHERE id(n) = id(kimDeal))
|RETURN extract(node in nodes(pathx) | id(node)) as ids
Copy link
Contributor

@Mats-SX Mats-SX Jan 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not saying you need to change this, but the fancy way of doing extract is through list comprehensions: [node IN nodes(pathx) | id(node)] AS ids

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that was only in 3.1 and later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct! I forgot that this was 3.0

@Mats-SX Mats-SX merged commit 563c765 into neo4j:3.0 Jan 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants