Procedure `apoc.meta.subgraph` return wrong type with `includeLabels` not existent
Issue by vga91
Monday May 17, 2021 at 10:35 GMT
Originally opened as https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/1906
Expected Behavior (Mandatory)
Should return nodes: [] and relationships: []
Actual Behavior (Mandatory)
The procedure returns a node with dataset total count.
How to Reproduce the Problem
Simple Dataset (where it's possibile)
CREATE (:Foo), (:Bar)
Steps (Mandatory)
CALL apoc.meta.subGraph({labels:["Test"],rels:[],excludes:[]})- Returns a
"Test"node with count 2, even if the label does not exist
Screenshots (where it's possibile)
Currently used versions
Versions
- Neo4j: 4.0.11
- Neo4j-Apoc: 4.0.0.18
Comment by vga91
Monday May 17, 2021 at 12:57 GMT
Related to #1491 (Same root cause, but without rels)
Here is a little more detailed variant (on 5.25.1)
Setup:
MATCH (n) DETACH DELETE n
WITH COUNT(1) as foo
CREATE (:Foo), (:Bar), (:Test) // label Test created here
WITH COUNT(1) as foo
MATCH (t:Test) DELETE t // node with label Test delete again
WITH COUNT(1) as foo
MATCH (n)
RETURN n
Query 1:
CALL apoc.meta.subGraph({includeLabels:["Test"],rels:[],excludes:[]})
=> correct result
Query 2:
CALL apoc.meta.subGraph({includeLabels:["X"],rels:[],excludes:[]})
=> wrong result
In other words, truly unknown labels are effected.
Note that
CALL db.labels
is not indicator which labels are effected, since it does not return Test label after the above setup query.
The same issue appear on the function apoc.meta.nodes.count. On the above setup:
RETURN apoc.meta.nodes.count(["Test"]) AS cnt
correctly returns
╒═══╕
│cnt│
╞═══╡
│0 │
└───┘
while
RETURN apoc.meta.nodes.count(["X"]) AS cnt
erroneously returns
╒═══╕
│cnt│
╞═══╡
│2 │
└───┘
Like the result of apoc.meta.nodes.count, the count property on the create virtual node wrongly created by apoc.meta.subGraph seems to always be 2.
A similar problem also exists for relationship types.
Setup
MATCH (n) DETACH DELETE n
WITH COUNT(1) as foo
CREATE (:Foo)-[:R]->(:Bar)-[:Rtest]->(:Test)
WITH COUNT(1) as foo
MATCH (t:Test) DETACH DELETE t
WITH COUNT(1) as foo
MATCH (n)
RETURN n
Query 1:
CALL apoc.meta.subGraph({includeLabels:["R"],rels:[],excludes:[]})
=> correct result
Query 2:
CALL apoc.meta.subGraph({includeLabels:[],rels:["Rtest"],excludes:[]})
=> correct result
Query 3:
CALL apoc.meta.subGraph({includeLabels:[],rels:["X"],excludes:[]})
=> wrong result
Here the made up count is 1 though.
Query 4:
CALL apoc.meta.subGraph({includeLabels:["Bar"],rels:["X"],excludes:[]})
=> correct result, interestingly
Query 5:
CALL apoc.meta.subGraph({includeLabels:["X"],rels:["X"],excludes:[]})
=> wrong result, again