RELATE is no more

51 views
Skip to first unread message

Andres Taylor

unread,
Jul 20, 2012, 7:46:06 AM7/20/12
to neo4j
Hey guys,

Wanted to share this before we make a release out of it.

An important feature for Cypher is to permit idempotent queries. Instead of checking the current state of the graph and then deciding which changes to do, we want users to specify the desired outcome, and leave it up to Cypher to figure out what needs doing to make that outcome real.

An example of that is when you want a pattern to be unique. Between the Andrés node and the Mimi node, there should only be a single MARRIED relationship. Another example is the get-from-index-or-create-and-insert-into-index.

RELATE does not reflect this strongly enough, and I keep seeing people on the mailing list and on Stackoverflow that misunderstand what RELATE is and how it's intended to be used.

So, the plan is to use the same clause for get-or-creating unique nodes, and for get-or-creating unique patterns in the graph. The new keyword will be CREATE UNIQUE.

It works just as RELATE did (it's only a parser change), but it more clearly expresses the uniqueness constraint. CREATE UNIQUE does a lot more checks and locking than CREATE does, and this change should make that a lot clearer.

The actual code change is here, if anyone is curious: https://github.com/neo4j/community/pull/724



I'm really sorry that this comes so late in our release cycle for 1.8 - I didn't understand enough sooner to realize this. At the same time, I really don't want to make a public stable release with RELATE and then change it in the first milestone.

Like always - any and all feedback is most welcome.

--
The best way to ask for Cypher help: http://console.neo4j.org/usage.html 

Nigel Small

unread,
Jul 20, 2012, 7:48:52 AM7/20/12
to ne...@googlegroups.com
Hmmmm.... in that case I'd better schedule an urgent patch for py2neo :-/

Andres Taylor

unread,
Jul 20, 2012, 7:53:29 AM7/20/12
to ne...@googlegroups.com
On Fri, Jul 20, 2012 at 1:48 PM, Nigel Small <ni...@nigelsmall.net> wrote:
Hmmmm.... in that case I'd better schedule an urgent patch for py2neo :-/

Sorry, and thanks Nigel. I'll buy the beers next time.

Andrés 

Peter Neubauer

unread,
Jul 20, 2012, 10:03:00 AM7/20/12
to ne...@googlegroups.com
Good decision Andres!

And I think this will be much more in line with the indexing semantics that then come natural form this - CREATE UNIQUE works then both for unique patters (now) and for unique nodes/rels (backed by indexes or other means) later.

/peter


--

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.

Nigel Small

unread,
Jul 21, 2012, 6:36:51 AM7/21/12
to ne...@googlegroups.com
I have updated py2neo to replace "RELATE" with "CREATE UNIQUE" and renamed the "relate" method to "get_or_create_relationships". However, it still looks like there's a failing test which involves passing an array property into such a relationship. I'm using a snapshot downloaded today and have not been able to find a related issue on GitHub. I'm happy to raise one if necessary.

The error scenario can be recreated with:

curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{"query":"START a0=node(120),b0=node(121) CREATE UNIQUE a0-[r0:`LIKES` {D0}]->b0 RETURN r0","params":{"D0":{"colours":["red","green"]}}}' http://localhost:7474/db/data/cypher

But works fine with:

curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{"query":"START a0=node(120),b0=node(121) CREATE UNIQUE a0-[r0:`LIKES` {D0}]->b0 RETURN r0","params":{"D0":{"colours":"red"}}}' http://localhost:7474/db/data/cypher

The actual error returned is:

{
  "message" : "Unknown property type on: [red, green], class java.util.ArrayList",
  "exception" : "IllegalArgumentException",
  "stacktrace" : [ "org.neo4j.kernel.impl.nioneo.store.PropertyStore.encodeValue(PropertyStore.java:570)",
    .......
  ]
}

Cheers
Nige

Aseem Kishore

unread,
Jul 23, 2012, 4:30:31 PM7/23/12
to ne...@googlegroups.com
I think this is a great change -- I'm also *so* excited to have CREATE UNIQUE that works w/ indexes. That'll solve perhaps the biggest concurrency hole in Neo4j's REST API right now!

Keep up the great work guys.

Aseem

P.S. Okay, I admit it. I was never a fan of the word RELATE. It didn't make much sense to me. I just didn't want to be a downer with repeated negative feedback! ;)

Andres Taylor

unread,
Jul 24, 2012, 11:36:16 AM7/24/12
to ne...@googlegroups.com
On Mon, Jul 23, 2012 at 10:30 PM, Aseem Kishore <aseem....@gmail.com> wrote:
I think this is a great change -- I'm also *so* excited to have CREATE UNIQUE that works w/ indexes. That'll solve perhaps the biggest concurrency hole in Neo4j's REST API right now!

Thanks. It will take a while to get there, but it'll be glorious.
 
P.S. Okay, I admit it. I was never a fan of the word RELATE. It didn't make much sense to me. I just didn't want to be a downer with repeated negative feedback! ;)

You saved us all a lot of typing with your WITH suggestions, so please don't hold back next time. Nothing in Cypher is due to my original thinking. I'm just fortunate enough to be surrounded by brilliant people who have awesome ideas. And half the time I don't even realize how good the idea is until much later...

Andrés 
Reply all
Reply to author
Forward
0 new messages