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

Procedure apoc.meta.subgraph return wrong type with includeLabels not existent #68

Open
neo-technology-build-agent opened this issue Sep 1, 2022 · 3 comments
Labels
bug Something isn't working Processed

Comments

@neo-technology-build-agent
Copy link
Collaborator

Issue by vga91
Monday May 17, 2021 at 10:35 GMT
Originally opened as neo4j-contrib/neo4j-apoc-procedures#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)

  1. CALL apoc.meta.subGraph({labels:["Test"],rels:[],excludes:[]})
  2. Returns a "Test" node with count 2, even if the label does not exist

Screenshots (where it's possibile)

Schermata 2021-05-17 alle 12 33 26

Currently used versions

Versions

  • Neo4j: 4.0.11
  • Neo4j-Apoc: 4.0.0.18
@neo-technology-build-agent
Copy link
Collaborator Author

Comment by vga91
Monday May 17, 2021 at 12:57 GMT


Related to #1491 (Same root cause, but without rels)

@gem-neo4j gem-neo4j added the bug Something isn't working label Apr 6, 2023
@hvub
Copy link
Collaborator

hvub commented Nov 22, 2024

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.

@hvub
Copy link
Collaborator

hvub commented Nov 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Processed
Projects
None yet
Development

No branches or pull requests

4 participants