neo4jneo4j-embedded

Comprehension pattern and neo4j-embedded


I have a problem when using comprehension with a neo4j-embedded (version 3.5.3).

For exemple, this kind of query works perfectly fine with neo4j enterprise 3.5.3, but does not work with neo4j-embedded :

MATCH (myNode:MyNode {myId:'myid'})
MATCH path = ( (myNode) -[*0..]- (otherNode:MyNode) )
WHERE
    ALL(n in nodes(path) where [ (n)<--(state:MyState) | state.isConnected ][0] = true)
RETURN myNode, otherNode

The error I get when using neo4j-embedded is difficult to understand, and looks like an internal error :

org.neo4j.driver.v1.exceptions.DatabaseException: This expression should not be added to a logical plan:
VarExpand(myNode, BOTH, OUTGOING, List(), otherNode,   UNNAMED62, VarPatternLength(0,None), ExpandInto,   UNNAMED62_NODES,   UNNAMED62_RELS, Equals(ContainerIndex(PatternComprehension(None,RelationshipsPattern(RelationshipChain(NodePattern(Some(Variable(  UNNAMED62_NODES)),List(),None,None),RelationshipPattern(Some(Variable(  REL136)),List(),None,None,INCOMING,false,None),NodePattern(Some(Variable(state)),List(LabelName(MyState)),None,None))),None,Property(Variable(state),PropertyKeyName(isConnected))),Parameter(  AUTOINT1,Integer)),True()), True(), List((Variable(n),Equals(ContainerIndex(PatternComprehension(None,RelationshipsPattern(RelationshipChain(NodePattern(Some(Variable(n)),List(),None,None),RelationshipPattern(Some(Variable(  REL136)),List(),None,None,INCOMING,false,None),NodePattern(Some(Variable(state)),List(LabelName(MyState)),None,None))),None,Property(Variable(state),PropertyKeyName(isConnected))),Parameter(  AUTOINT1,Integer)),True())))) {
  LHS -> CartesianProduct() {
    LHS -> Selection(Ands(Set(In(Property(Variable(myNode),PropertyKeyName(myId)),ListLiteral(List(Parameter(  AUTOSTRING0,String))))))) {
      LHS -> NodeByLabelScan(myNode, LabelName(MyNode), Set()) {}
    }
    RHS -> NodeByLabelScan(otherNode, LabelName(MyNode), Set()) {}
  }
}

Any idea ?


Solution

  • It was quite a complicated issue but here is the full explanation. First, I found that it was not specific to neo4j-embedded. The internal error exception was raised because of an assert in Neo4J, witch would trigger an exception only if the flag -ea (enable assertions) is set. And this flag is set only when running tests with maven or any IDE.

    Drilling down Neo4J's code on github, I found also that this assert whas added because of some concerns on recursive comprehension pattern. (The commit is here : https://github.com/neo4j/neo4j/commit/dfbe8ce397f7b72cf7d9b9ff1500f24a5c4b70b0)

    In my case, I do use comprehension pattern but not recursively, so I think everything should be fine, except when unit testing :)

    I submitted the problem to Neo4J's support, and they will provide a fix in a future release.