'cutting of' a node with all subnodes

44 views
Skip to first unread message

wujek

unread,
Oct 2, 2012, 3:25:46 AM10/2/12
to ne...@googlegroups.com
Hi. I have the following structure:


REF_NODE
    |
    |
    |
some node
|    |    |    |
a  b   c   d


Nodes a, b, c and d also have other nodes. The point is - there is only a single reference to 'some node' from REF_NODE and for each of its children. I would like to be able to delete 'some node' with all nodes that are 'under it' - that's what I mean by cutting off, for lack of a better, scientific word ;d There can, however, be references between all other nodes below 'some node' (for example, a references c, and grandchildren of d reference b and the other way round). For the delete operation, it's all the same as long as there are no references to the 'top level' 'some node'.
The Node.delete() method will not allow me to delete it as there are other references. The way I can see it work is to have some complex algorithm to 'disintegrate' the graph somehow, which I think would be difficult and time consuming - the subgraph below 'some node' might be very big indeed.
How can I do it best?

Regards,
wujek

Mattias Persson

unread,
Oct 2, 2012, 3:49:31 AM10/2/12
to ne...@googlegroups.com
I don't quite understand as your sentences seem to contradict each other.

On the one hand you'd like to delete "some node" and "all nodes under it".

On the other hand you'd just like to cut it off, which I interpret as just remove all its relationships.

Can you elaborate?

Best,
Mattias

2012/10/2 wujek <wujek....@gmail.com>

--
 
 



--
Mattias Persson, [mat...@neotechnology.com]
Hacker, Neo Technology
www.neotechnology.com

Wujek Srujek

unread,
Oct 2, 2012, 3:55:39 AM10/2/12
to ne...@googlegroups.com
Sorry for the poor wording and confusion.
By cutting off I mean: wipe out 'some node', a, b, c, d, all other nodes below, all relationships... I would like to say:
node.wipeOut()
and have the whole subgraph deleted - after this operation, the graph looks like the following:

REF_NODE

Of course, if the graph looks like this:

REF_NODE
|                |
|                |
some        another
node         node

and I invoke

'some node'.wipeOut()

the graph looks like this:

REF_NODE
                 |
                 |
               another
               node

(again, with no trace of orphaned 'some node', a, b, c, or d).


Regards,
wujek


--
 
 

Wes Freeman

unread,
Oct 2, 2012, 3:55:24 AM10/2/12
to ne...@googlegroups.com
I think he wants to prune the tree starting at a node, but not including that node. I'm also interested in this ability (it would be nice not to have to traverse and prune). Is there syntax that allows for this already? 

--
 
 

Wujek Srujek

unread,
Oct 2, 2012, 3:57:09 AM10/2/12
to ne...@googlegroups.com
Thank you! Yes, 'prune' would be the better word.

With the difference that when I prune starting with a node, I also want to remove the node itself. But that should be a simple change?

wujek

--
 
 

Wes Freeman

unread,
Oct 2, 2012, 4:00:23 AM10/2/12
to ne...@googlegroups.com
I think the syntax to delete collections of relationships in cypher would make this trivial (either deleting the starting node or not), as I mentioned in my ticket. I don't think there's another way to do it without doing multiple calls and traversing.

Wes

--
 
 

Wujek Srujek

unread,
Oct 2, 2012, 4:17:11 AM10/2/12
to ne...@googlegroups.com
Great, I will test it. Thank you for your help.
One question - you said no traversal is done - how does this work then? Does cypher don't do traversal in this case?
Sorry for this potentially dumb question, I am just starting with neo4j, and haven't looked at cypher yet!

Regards,
wujek


--
 
 

Michael Hunger

unread,
Oct 2, 2012, 5:05:02 AM10/2/12
to ne...@googlegroups.com
Wes was almost right on the syntax, the only difference is that "r" is an collection. So you have to use foreach to delete it.

start n=node({lookup})
match n-[r*]->m
where not(m-[*]->n)
foreach (rel in r: delete rel)
delete m;

--
 
 

Reply all
Reply to author
Forward
0 new messages