Skip to content

Instantly share code, notes, and snippets.

@ernestoe
Last active August 29, 2015 14:21
Show Gist options
  • Save ernestoe/85a5301ff283fd95e19a to your computer and use it in GitHub Desktop.
Save ernestoe/85a5301ff283fd95e19a to your computer and use it in GitHub Desktop.

Is this a binding bug?

Start with an empty database and load sample data

Launch your favorite neo4j browser and run the following, in a clean database. If you have existing data, the queries are slow as they will match all existing nodes.

create (_30:`MetaNode` {`name`:"Category"})
create (_32:`MetaNode` {`name`:"Review"})
create (_34:`MetaNode` {`name`:"Ambiguous"})
create (_40:`MetaNode` {`name`:"GlobalTemplateCategory"})
create (_41:`MetaNode` {`name`:"MappingReview"})
create (_42:`MetaNode` {`name`:"ClassificationReview"})
create _30-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_34
create _30-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_32
create _30-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_30
create _32-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_30
create _32-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_40
create _32-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_42
create _32-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_32
create _34-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_30
create _34-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_40
create _34-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_32
create _40-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_42
create _40-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_34
create _40-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_41
create _40-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_32
create _40-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_40
create _41-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_40
create _42-[:`META_RELATIONSHIP` {`name`:"GROUPED_BY"}]->_40
;

This is how it looks graphically

The loops don't show in a graphgist, but they should look fine in a Neo4j 2.2+ browser.

1st query showcasing the problem

MATCH
  p=(n1)-[r1]->(n2)<-[r2]-(n1)
WHERE
  type(r1)=type(r2) AND
  split(split(str(r1),"{")[1],"}")[0] = split(split(str(r2),"{")[1],"}")[0] // filter only those with same properties
RETURN
  str(n1), str(r1), str(n2), str(r2), str(p)

Apparently Neo4j 2.1 doesn’t have the problem as no records are shown in the results. However Neo4j 2.2 has the problem and would show 6 records. When inspecting you can see the end node of the path is not the same as the starting node.

2nd query showcasing the problem

MATCH
  p=(n1)-[r1]->(n2), q=(n1)-[r2]->(n2)
WHERE
  type(r1)=type(r2) AND
  split(split(str(r1),"{")[1],"}")[0] = split(split(str(r2),"{")[1],"}")[0] // filter only those with same properties
RETURN
  str(n1), str(r1), str(n2), str(r2), str(p), str(q)

Identical to the previous result, however the MATCH clause has been split. Again, it shows in Neo4j 2.2.

3rd query without issues

MATCH
  p=(n1)-[r1]->(n2), q=(n3)-[r2]->(n4)
WHERE
  n1=n3 AND n2=n4 AND
  type(r1)=type(r2) AND
  split(split(str(r1),"{")[1],"}")[0] = split(split(str(r2),"{")[1],"}")[0] // filter only those with same properties
RETURN
  str(n1), str(r1), str(n2), str(r2), str(p), str(q)

of course, this last query is the most inefficient one, don’t even try to run with a normal size dataset. In Neo4j 2.2 this is the one query that won’t show any results. In my view all 3 queries are equivalent.

Is this the expected behaviour?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment