Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed how the graph-matching module is used, to make it safe for co…

…ncurrent use
  • Loading branch information...
commit a60fe3e6c456bec8ffa328989c0e849aa4b8efc0 1 parent 9e3eaf0
@systay authored
View
24 cypher/src/main/scala/org/neo4j/cypher/internal/pipes/matching/SimplePatternMatcherBuilder.scala
@@ -19,24 +19,26 @@
*/
package org.neo4j.cypher.internal.pipes.matching
-import collection.Map
+import collection.{immutable, Map}
import org.neo4j.graphdb.{Relationship, Node, DynamicRelationshipType}
-import org.neo4j.graphmatching.{PatternMatcher => SimplePatternMatcher, PatternNode => SimplePatternNode}
+import org.neo4j.graphmatching.{PatternMatcher => SimplePatternMatcher, PatternNode => SimplePatternNode, PatternRelationship=>SimplePatternRelationship, PatternGroup}
import collection.JavaConverters._
import org.neo4j.cypher.internal.commands.{Predicate, True}
import org.neo4j.cypher.internal.symbols.SymbolTable
import org.neo4j.cypher.internal.pipes.MutableMaps
class SimplePatternMatcherBuilder(pattern: PatternGraph, predicates: Seq[Predicate], symbolTable: SymbolTable) extends MatcherBuilder {
- val patternNodes = pattern.patternNodes.map {
- case (key, pn) => {
- key -> {
- new SimplePatternNode(pn.key)
+ def createPatternNodes: immutable.Map[String, SimplePatternNode] = {
+ pattern.patternNodes.map {
+ case (key, pn) => {
+ key -> {
+ new SimplePatternNode(pn.key)
+ }
}
}
}
- val patternRels = pattern.patternRels.map {
+ def createPatternRels(patternNodes:immutable.Map[String, SimplePatternNode]):immutable.Map[String, SimplePatternRelationship] = pattern.patternRels.map {
case (key, pr) => {
val start = patternNodes(pr.startNode.key)
val end = patternNodes(pr.endNode.key)
@@ -55,7 +57,9 @@ class SimplePatternMatcherBuilder(pattern: PatternGraph, predicates: Seq[Predica
}
}
- def setAssociations(sourceRow: Map[String, Any]) {
+ def setAssociations(sourceRow: Map[String, Any]): (immutable.Map[String, SimplePatternNode], immutable.Map[String, SimplePatternRelationship]) = {
+ val patternNodes = createPatternNodes
+ val patternRels = createPatternRels(patternNodes)
patternNodes.values.foreach(pn => {
sourceRow.get(pn.getLabel) match {
case Some(node: Node) => pn.setAssociation(node)
@@ -69,10 +73,12 @@ class SimplePatternMatcherBuilder(pattern: PatternGraph, predicates: Seq[Predica
case _ => pr.setAssociation(null)
}
})
+
+ (patternNodes, patternRels)
}
def getMatches(sourceRow: Map[String, Any]) = {
- setAssociations(sourceRow)
+ val (patternNodes, patternRels) = setAssociations(sourceRow)
val result = MutableMaps.create(sourceRow)
val validPredicates = predicates.filter(p => symbolTable.satisfies(p.dependencies))
val startPoint = patternNodes.values.find(_.getAssociation != null).get
Please sign in to comment.
Something went wrong with that request. Please try again.