GeezerVison is showing github.com — Cypher: Returned edges (serialised) are not filtered by query · Issue #673 · ArcadeData/arcadedb
Cypher: Returned edges (serialised) are not filtered by query #673DescriptionArcadeDB Version: 22.11.1
JDK Version: Docker image
OS:Linux
Expected behavior
Query with edge type should return only those edges:
MATCH (p:Person)-[:IS_COORDINATOR_OF]->(pr:Project) RETURN p, pr
Actual behavior
Returned set (serialised with 'graph' option) includes all edges between selected nodes.
Steps to reproduce
Create a simple graph, two persons and two projects.
CREATE (p:Person {name: "Bob"})-[:IS_COORDINATOR_OF]->(pr:Project {name: "Bob's Project"}) RETURN p, pr
CREATE (p:Person {name: "Jenny"})-[:IS_COORDINATOR_OF]->(pr:Project {name: "Jenny's Project"}) RETURN p, pr
MATCH (p:Person {name: "Bob"}), (pr:Project {name:"Jenny's Project"}) CREATE (p)-[:IS_MEMBER_OF]->(pr) return p,pr
MATCH (p:Person {name: "Jenny"}), (pr:Project {name:"Bob's Project"}) CREATE (p)-[:IS_MEMBER_OF]->(pr) return p,pr
Then try to get project coordinators:
MATCH (p:Person)-[:IS_COORDINATOR_OF]->(pr:Project) RETURN p, pr
{
"result": {
"vertices": [
{
"p": {
"name": "Bob"
},
"r": "#10:0",
"t": "Person",
"i": 0,
"o": 2
},
{
"p": {
"name": "Bob's Project"
},
"r": "#28:0",
"t": "Project",
"i": 2,
"o": 0
},
{
"p": {
"name": "Jenny"
},
"r": "#13:0",
"t": "Person",
"i": 0,
"o": 2
},
{
"p": {
"name": "Jenny's Project"
},
"r": "#31:0",
"t": "Project",
"i": 2,
"o": 0
}
],
"records": [
{
"p": {
"@rid": "#10:0",
"@type": "Person",
"name": "Bob"
},
"pr": {
"@rid": "#28:0",
"@type": "Project",
"name": "Bob's Project"
}
},
{
"p": {
"@rid": "#13:0",
"@type": "Person",
"name": "Jenny"
},
"pr": {
"@rid": "#31:0",
"@type": "Project",
"name": "Jenny's Project"
}
}
],
"edges": [
{
"p": {},
"r": "#51:0",
"t": "IS_COORDINATOR_OF",
"i": "#31:0",
"o": "#13:0"
},
{
"p": {},
"r": "#57:0",
"t": "IS_MEMBER_OF",
"i": "#31:0",
"o": "#10:0"
},
{
"p": {},
"r": "#50:0",
"t": "IS_COORDINATOR_OF",
"i": "#28:0",
"o": "#10:0"
},
{
"p": {},
"r": "#57:0",
"t": "IS_MEMBER_OF",
"i": "#31:0",
"o": "#10:0"
},
{
"p": {},
"r": "#50:0",
"t": "IS_COORDINATOR_OF",
"i": "#28:0",
"o": "#10:0"
},
{
"p": {},
"r": "#58:0",
"t": "IS_MEMBER_OF",
"i": "#28:0",
"o": "#13:0"
},
{
"p": {},
"r": "#51:0",
"t": "IS_COORDINATOR_OF",
"i": "#31:0",
"o": "#13:0"
},
{
"p": {},
"r": "#58:0",
"t": "IS_MEMBER_OF",
"i": "#28:0",
"o": "#13:0"
}
]
},
"user": "root",
"version": "22.11.1 (build 8c5ff1d46513ac0b324e45f7f59f1a42150dd471/1670448994340/main)"
}
Activitylvca commented on Dec 18, 2022 The graph mode returns all the edges connected. It's useful, mostly, for rendering. What you're looking for here, I guess, is only the returned records from Cypher that you can actually find under "records" property in the JSON. Could you please execute the same query with "record" mode instead of "graph"? artturimatias commented on Dec 18, 2022 Thanks Luca for watching this.
I wasn't accurate with my original question. What I need is:
"Get all project coordinators, their projects and render result as a graph without any extra edges"
So edge filtering is needed for rendering purposes. In my app, the graph is part of the user interface and it should be as clean as possible.
Could this be optional query parameter?
EDIT. Maybe its good to mention that if one tries this in Neo4J UI you actually get all the edges, but that's done with extra query in the UI. There's option where you can turn this feature off. lvca commented on Dec 22, 2022 @artturimatias I see now, thanks for the clarification. We could introduce a new serializer that strictly serializes the resultset in vertices and edges properties. Who can come up with a nice name? "graph" is already taken. We should rename "graph" in "studio" but we'd break the compatibility with the existent codebase. What about:
- strictgraph
- graph!
- !graph
- resultset-graph
artturimatias commented on Dec 22, 2022 "strictgraph" sounds meaningful to me. lvca commented on Dec 23, 2022 I was able to implement "strictgraph" (if anyone comes up with a better name, I'd be glad to rename it) and with that query I didn't see any edge:
MATCH (p:Person)-[:IS_COORDINATOR_OF]->(pr:Project) RETURN p, pr
That's because edges were not part of the result set. If you do this with the new "strictgraph" works:
MATCH (p:Person)-[e:IS_COORDINATOR_OF]->(pr:Project) RETURN p, pr, e

Also, in this mode the "record" attribute is not filled up, just "vertices" and "edges" resulting in a much lighter JSON.
@artturimatias WDYT? lvca commented on Dec 23, 2022 This is the JSON with "strictgraph":
{
"result": {
"vertices": [
{
"p": {
"name": "Bob"
},
"r": "#25:0",
"t": "Person",
"i": 0,
"o": 2
},
{
"p": {
"name": "Bob's Project"
},
"r": "#49:0",
"t": "Project",
"i": 2,
"o": 0
},
{
"p": {
"name": "Bob"
},
"r": "#25:0",
"t": "Person",
"i": 0,
"o": 2
},
{
"p": {
"name": "Bob's Project"
},
"r": "#49:0",
"t": "Project",
"i": 2,
"o": 0
},
{
"p": {
"name": "Jenny"
},
"r": "#28:0",
"t": "Person",
"i": 0,
"o": 2
},
{
"p": {
"name": "Jenny's Project"
},
"r": "#52:0",
"t": "Project",
"i": 2,
"o": 0
},
{
"p": {
"name": "Jenny"
},
"r": "#28:0",
"t": "Person",
"i": 0,
"o": 2
},
{
"p": {
"name": "Jenny's Project"
},
"r": "#52:0",
"t": "Project",
"i": 2,
"o": 0
}
],
"edges": [
{
"p": {},
"r": "#73:0",
"t": "IS_COORDINATOR_OF",
"i": "#49:0",
"o": "#25:0"
},
{
"p": {},
"r": "#74:0",
"t": "IS_COORDINATOR_OF",
"i": "#52:0",
"o": "#28:0"
}
]
},
"user": "root",
"version": "22.12.1 (build 08eb71f7264ba1eacd872632dcd2162765ddb67e/1671833658668/main)"
}lvca commented on Dec 24, 2022 It's now in the main branch. Please let me know when you have time if this is what you were looking for or if anything else is missing. lvca commented on Dec 24, 2022 After many thoughts, I'd prefer to change "graph" to serializing only the graph element. This is because everybody is using "graph" but nobody is interested in the "record" collections, and it's a waste of RAM and bandwidth.
So I'm going to rename "strictgraph" to just "graph" and the old "graph" in "studio", because it's the way Studio mainly interacts to get both graph and record elements. The graph is to draw the graph, records to fill the table. lvca commented on Dec 24, 2022 99% of the user would not notice any difference, because the JSON format is the same, but for the "records" property only Studio seems to be interested. Also, the "vertices" and "edges" content is the strict resultset, with nothing more added. The additional vertices were done for Studio, so again, "graph" should be the natural way to get the resultset as a graph. artturimatias commented on Jan 2, 2023 Tested with latest main branch and now I can get clean result.
Sorry for delayed testing and huge thanks for the fix.
One more thing: "Graph" serializer gives vertices twice as you can see your JSON above? lvca commented on Jan 2, 2023 @artturimatias I didn't see any duplicates, they should be removed on the server side before sending them to the client via HTTP. if you notice this issue again with a new release, please reopen this issue. artturimatias commented on Jan 3, 2023 Hmm, I think I can not re-open this since I did not close this issue. However, the issue of duplicates exists.
With the graph that was created in the initial issue, this query gives all vertices twice (with identical properties):
MATCH (p:Person)-[r:IS_COORDINATOR_OF]->(pr:Project) RETURN r,p, pr
request:
curl -X POST http://localhost:2480/api/v1/command/testi -d '{ "language": "cypher", "command": "MATCH (p:Person)-[r:IS_COORDINATOR_OF]->(pr:Project) RETURN r,p, pr", "serializer": "graph"}' -H "Content-Type: application/json" --user root:passwd
result:
{
"result": {
"edges": [
{
"i": "#25:0",
"o": "#13:0",
"p": {},
"r": "#49:0",
"t": "IS_COORDINATOR_OF"
},
{
"i": "#28:0",
"o": "#16:0",
"p": {},
"r": "#50:0",
"t": "IS_COORDINATOR_OF"
}
],
"vertices": [
{
"i": 0,
"o": 2,
"p": {
"name": "Bob"
},
"r": "#13:0",
"t": "Person"
},
{
"i": 2,
"o": 0,
"p": {
"name": "Bob's Project"
},
"r": "#25:0",
"t": "Project"
},
{
"i": 0,
"o": 2,
"p": {
"name": "Bob"
},
"r": "#13:0",
"t": "Person"
},
{
"i": 2,
"o": 0,
"p": {
"name": "Bob's Project"
},
"r": "#25:0",
"t": "Project"
},
{
"i": 0,
"o": 2,
"p": {
"name": "Jenny"
},
"r": "#16:0",
"t": "Person"
},
{
"i": 2,
"o": 0,
"p": {
"name": "Jenny's Project"
},
"r": "#28:0",
"t": "Project"
},
{
"i": 0,
"o": 2,
"p": {
"name": "Jenny"
},
"r": "#16:0",
"t": "Person"
},
{
"i": 2,
"o": 0,
"p": {
"name": "Jenny's Project"
},
"r": "#28:0",
"t": "Project"
}
]
},
"user": "root",
"version": "23.1.1-SNAPSHOT (build 38b56de872c22a21595dad603287b774d8f27dd6/1672688800312/main)"
}
lvca commented on Jan 3, 2023 Reproduced, you're right. lvca commented on Jan 3, 2023 Fixed in 5575c3d. Tested with your resultset and the records aren't duplicated anymore. Please let me know if you can confirm it. artturimatias commented on Jan 3, 2023 Tested and duplicates are gone. Many thanks!
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|