Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-15-2022 03:56 AM
Hi all. I want to hide some of the data returned in my path by using virtual nodes/relations.
I created the virtual nodes successfully but upon returning the path, it is still showing the nodes and relations i am trying to hide. Is there any way that I can return the virtual relation in the same path object without creating a new object?
eg: original path = A->B->C->D->E (nodes to be hidden = c Therefore, if i want to replace it with a virtual relation then my path effectively should be A->B->D->E)
Although my virtual relationship is successfully created bw B and D node, it still returns the C node as well as A->c and C->D relations. Thanks in advance
12-15-2022 06:29 AM
Can you post her query?
12-15-2022 09:45 PM
call {
match path = (n:A{Name:"xyz"})<-[e:BelongsTo]-(p:B)<-[:BelongsTo]-(ps:C)-[r:CanAccess]->(k)
return n as Identity, e as edge, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p
union
match path = (n:A{Name:"xyz"})-[e:Uses]->(p:D)<-[:BelongsTo]-(:D)<-[:BelongsTo]-(:C)-[r:CanAccess]->(k)
return n as Identity, e as edge, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p
union
match path = (n:A{Name:"xyz"})-[e:BelongsTo]->(:E)-[:Uses]->(p:D)<-[:BelongsTo]-(:D)<-[:BelongsTo]-(ps:C)-[r:CanAccess]->(k)
return n as Identity, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p, e as edge
union
match path = (n:A{Name:"xyz"})-[e:BelongsTo]->(:E)<-[:BelongsTo]-(p:E)<-[:BelongsTo]-(:C)-[r:CanAccess]->(k)
return n as Identity, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p, e as edge
union
match path = (k:F)-[e:BelongsTo]-(p:G)-[:BelongsTo]-(:G)-[r:isAttachedTo]->(n:A{Name:"xyz"})
return n as Identity, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p, e as edge
}
with collect(distinct Effect) as EffectList, Identity, Action, ResourceId, collect(path) as paths, collect(p) as policies, edge
where size(EffectList) = 1 and EffectList[0] = "Allow"
with EffectList, Identity, Action, ResourceId, paths, policies, edge
unwind policies as p
return apoc.create.vRelationship(p, 'MyEdge', {Effect:"Allow"}, ResourceId) as relations, Identity,edge
Basically for eg in the first match I want to skip "C" node in the path and directly connect B->k
12-15-2022 09:50 PM
This is the original path i am getting
I want to replace it with a new path:
12-28-2022 11:02 PM
@rudrakhsha any solution on this. are you able to crack on this. I am also facing similar issue.
Thanks in advance
12-29-2022 01:53 AM
Can you describe you situation, so someone we can help?
12-15-2022 10:56 PM
That is a lot. It is hard to understand how it relates to your graph. Anyways, try the following for the first path:
match (n:A{Name:"xyz"})<-[e:BelongsTo]-(p:B)<-[:BelongsTo]-(ps:C)-[r:CanAccess]->(k)
return n, e, p, k, apoc.create.vRelationship(p, 'MyEdge', {Effect:'Allow'}, k) as vRel
Also, you may be getting relationships you did not expect, as neo4j browser shows all relationships between displayed nodes by default. You can turn this off in the settings. Its the 'connect result nodes' checkbox at the bottom of the settings pane.
12-16-2022 02:52 AM
Thanks for the reply. I still had one doubt though. This will help me create a path with the virtual relation we created but in case I have some different path like the 3rd union where i have to travel different number of nodes, I will have to return a total of 5 objects then. Then in that case how do I create a virtual relation as Union queries wont allow sending different number of columns/relation alias in cypher query.
12-16-2022 03:05 AM
You could return ‘null’ for the missing values, so all the unions return the same number. Also use generic names so they all have the same names, i.e., node1, rel1, node2, rel2, …
what is all the collect and unwinds for at the end.
12-16-2022 03:07 AM
That is some logic level processing I am doing to filter out results according to my requirement...
12-16-2022 03:09 AM
Or, pack the results in an array, so each union returns a single item, then unwind the result to return the nodes and relationships. Arrays can contain elements of different types.
All the sessions of the conference are now available online