-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic labels/types #1098
Dynamic labels/types #1098
Conversation
[[dynamic-create]] | ||
== CREATE nodes and relationships using dynamic node labels and relationship types | ||
|
||
Node labels and relationship types can be referenced dynamically in parameters and variables when creating nodes and relationships. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we say they can be dynamically calculated from expressions? Because it isn't only parameters and variables that are allowed
[[dynamic-match]] | ||
== MATCH nodes and relationships using dynamic node labels and relationship types | ||
|
||
Node labels and relationship types can be referenced dynamically in parameters and variables when matching nodes and relationships. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about expressions
WITH "Movie" AS label | ||
MATCH (movie:$all(label)) | ||
RETURN movie AS movieNodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we are showcasing all explicitly then we should have more than one label and explain it is the conjunction
[NOTE] | ||
The xref:functions/predicate.adoc#functions-all[`all()`] function matches nodes that have all the specified labels. | ||
|
||
If passing a `LIST<STRING>` to an `all()` function evaluating a relationship pattern using dynamic relationship types, the list cannot contain more than one element. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can, it just won't match on anything (emitting a warning is not the same as disallowed) :)
MATCH (n:$any(["Movie", "Person"]))-[:ACTED_IN|DIRECTED]->(m:Movie) | ||
RETURN labels(n) AS labels, n.name AS person, collect(m.title) AS movies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe do a match without the relationship? then you don't have the non-dynamic part and the output can be just the nodes that are either movies or people
MATCH (n:$(<expr>)) | ||
MATCH (n:$any(<expr>)) | ||
MATCH (n:$all(<expr>)) | ||
---- | ||
|
||
.Syntax for matching relationship types dynamically | ||
[source, syntax] | ||
---- | ||
MATCH ()-[r:$(<expr>))]->() | ||
MATCH ()-[r:$any(<expr>)]->() | ||
MATCH ()-[r:$all(<expr>))]->() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be specified that all and not specifying one are the same meaning?
[[dynamic-merge]] | ||
== MERGE nodes and relationships using dynamic node labels and relationship types | ||
|
||
Node labels and relationship types can be referenced dynamically in parameters and variables when merging nodes and relationships. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same point about expressions
MERGE ()-[r:$(<expr>)]->() | ||
---- | ||
|
||
The expression must evaluate to a `STRING NOT NULL | LIST<STRING NOT NULL> NOT NULL` value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to mention maybe that relationships can still only have one type, even if a list is supplied
MATCH (movie:$($label)) | ||
---- | ||
|
||
[source, cypher, role="noheader"] | ||
---- | ||
CREATE (movie:$($label)) | ||
---- | ||
|
||
[source, cypher, role="noheader"] | ||
---- | ||
MERGE (movie:$($label)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is important to show the relationship syntax as well, as that is one of the main new things about this feature (SET and REMOVE cover all node cases for dynamic labels already, so this is just syntactic sugar for them)
CREATE (n:$(line.label) {name: line.Name}) | ||
---- | ||
|
||
| Added the ability reference node labels and relationship types in xref:clauses/match.adoc#dynamic-match[`MATCH`], xref:clauses/create.adoc#dynamic-create[`CREATE`], and xref:clauses/merge.adoc#dynamic-merge[`MERGE`] clauses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Added the ability reference node labels and relationship types in xref:clauses/match.adoc#dynamic-match[`MATCH`], xref:clauses/create.adoc#dynamic-create[`CREATE`], and xref:clauses/merge.adoc#dynamic-merge[`MERGE`] clauses. | |
| Added the ability to dynamically reference node labels and relationship types in xref:clauses/match.adoc#dynamic-match[`MATCH`], xref:clauses/create.adoc#dynamic-create[`CREATE`], and xref:clauses/merge.adoc#dynamic-merge[`MERGE`] clauses. |
.Syntax for creating nodes and relationships dynamically | ||
[source, syntax] | ||
---- | ||
CREATE (n:$(<expr>)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CREATE (n:$(<expr>)), | |
CREATE (n:$(<expr>)) |
.Syntax for merging nodes and relationships dynamically | ||
[source, syntax] | ||
---- | ||
MERGE (n:$(<expr>)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MERGE (n:$(<expr>)), | |
MERGE (n:$(<expr>)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Do we want to mention the performance issues with MATCH/MERGE?
@@ -205,10 +205,61 @@ Nodes created: 2 + | |||
Properties set: 4 | |||
|=== | |||
|
|||
[role=label--new-5.26] | |||
[[dynamic-create]] | |||
== CREATE nodes and relationships using dynamic node labels and relationship types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really long title, is it possible to make it shorter?
CREATE using dynamic node labels and relationship types
perhaps?
@@ -490,3 +492,124 @@ The above query uses the xref:functions/aggregating.adoc#functions-collect[`coll | |||
|
|||
For more information about how Cypher queries work, see xref:clauses/clause-composition.adoc[]. | |||
|
|||
[role=label--new-5.26] | |||
[[dynamic-match]] | |||
== MATCH nodes and relationships using dynamic node labels and relationship types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here:
MATCH using dynamic node labels and relationship types
---- | ||
|
||
[NOTE] | ||
The xref:functions/predicate.adoc#functions-any[`any()`] function matches nodes that have any of the specified labels. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like the any in the match is the any() function, but it isn't. It's behaviour is modeled off of the any function, but it is not identical, so maybe clarify this part a little more
|
||
[role=label--new-5.26] | ||
[[dynamic-merge]] | ||
== MERGE nodes and relationships using dynamic node labels and relationship types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MERGE using dynamic node labels and relationship types
Thanks for the documentation updates. The preview documentation has now been torn down - reopening this PR will republish it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
Co-authored-by: Stefano Ottolenghi <[email protected]>
Co-authored-by: Stefano Ottolenghi <[email protected]>
No description provided.