Re: Merge two vertices into one

427 views
Skip to first unread message

Josh Adell

unread,
Jul 29, 2012, 1:22:44 PM7/29/12
to ne...@googlegroups.com
This is an interesting idea. My question would be: why make a new 3rd node (C), instead of using one of the existing nodes, A or B? This would prevent the operations of creating a node, then moving all the relationships of A and B; you'd only have to move relationships on A or B.

Also, what happens to properties that exist on both A and B? If they both have a "foo" property, and on A the value is "bar" and on B the value is "baz" what is the value of "foo" on the merged node C?

If there is a clear definition of what the expected outcome and behavior is, this could be a pretty useful feature.

-- Josh

On Sunday, July 29, 2012 8:20:39 AM UTC-4, Макс Бартенев wrote:
Define merge operation for 2 vertices:
Let's we have 2 vertices A and B. Then we create new vertex C.
Then all outgoing edges from A and B become outgoing edges from C;
And all incoming edges to A and B become incoming edges to C;
Then vertices A and B remove; C becomes merge of A and B.

So the question is: does neo4j have any internal feautures for this operations?
Thank you.

P.S. Sorry for my English.

Michael Hunger

unread,
Jul 29, 2012, 1:36:38 PM7/29/12
to ne...@googlegroups.com
I like Josh's thoughts.
You could determine prop precedence by the order in which you merge the two.

When cypher gets the props() function it would be possible another thing is to use an expression for a rel-type

Sent from mobile device

Peter Neubauer

unread,
Jul 29, 2012, 2:30:06 PM7/29/12
to ne...@googlegroups.com
Is Cypher getting that function! Yay!

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Wanna learn something new? Come to @graphconnect.

Макс Бартенев

unread,
Jul 30, 2012, 4:28:18 AM7/30/12
to ne...@googlegroups.com
Yes, you are right about 3rd node. There's not necessary to create new one and I can use A or B.
About properties: I don't have any properties at nodes in my problem.

воскресенье, 29 июля 2012 г., 21:22:44 UTC+4 пользователь Josh Adell написал:

Michael Hunger

unread,
Jul 30, 2012, 5:29:24 AM7/30/12
to ne...@googlegroups.com
Do you have more than one rel-type?

Right now cypher doesn't support expressions for rel-types yet.

If you don't then it is as simple as this, you can even transfer well-known properties from the relationship.

start a=node(1),b=node(2),c=node(3)
match a-[r:TYPE]->b
create a-[:TYPE { foo : r.foo } ]->c
delete r
delete b

Niels Hoogeveen

unread,
Jul 30, 2012, 6:24:09 AM7/30/12
to ne...@googlegroups.com
As an extention to Cypher, I am agnostic to this feature request. Though I am not in favour of adding this to the java API, since it is functionality that can not be made generic enough to make it apply to all merge situations. Property precedence has already been mentioned and merging of relationships is even more complicated. Of course it's possible to simply take all relationships from the two nodes and make those the relationships of the merged node, but there are plenty of scenarios where that is not the required result.
 
Niels
Reply all
Reply to author
Forward
0 new messages