Skip to content
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

Merged
merged 21 commits into from
Nov 19, 2024
Merged

Dynamic labels/types #1098

merged 21 commits into from
Nov 19, 2024

Conversation

JPryce-Aklundh
Copy link
Contributor

No description provided.

@JPryce-Aklundh JPryce-Aklundh marked this pull request as draft November 5, 2024 09:17
[[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.
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about expressions

Comment on lines 520 to 522
WITH "Movie" AS label
MATCH (movie:$all(label))
RETURN movie AS movieNodes
Copy link
Contributor

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.
Copy link
Contributor

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) :)

Comment on lines 558 to 559
MATCH (n:$any(["Movie", "Person"]))-[:ACTED_IN|DIRECTED]->(m:Movie)
RETURN labels(n) AS labels, n.name AS person, collect(m.title) AS movies
Copy link
Contributor

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

Comment on lines 502 to 512
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>))]->()
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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

Comment on lines 88 to 98
MATCH (movie:$($label))
----

[source, cypher, role="noheader"]
----
CREATE (movie:$($label))
----

[source, cypher, role="noheader"]
----
MERGE (movie:$($label))
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| 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>)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CREATE (n:$(<expr>)),
CREATE (n:$(<expr>))

.Syntax for merging nodes and relationships dynamically
[source, syntax]
----
MERGE (n:$(<expr>)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MERGE (n:$(<expr>)),
MERGE (n:$(<expr>))

@JPryce-Aklundh JPryce-Aklundh marked this pull request as ready for review November 14, 2024 13:41
Copy link
Contributor

@gem-neo4j gem-neo4j left a 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
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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

@neo-technology-commit-status-publisher
Copy link
Collaborator

Thanks for the documentation updates.

The preview documentation has now been torn down - reopening this PR will republish it.

Copy link
Contributor

@gem-neo4j gem-neo4j left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@JPryce-Aklundh JPryce-Aklundh merged commit d6b2f98 into neo4j:dev Nov 19, 2024
4 of 5 checks passed
@JPryce-Aklundh JPryce-Aklundh deleted the dynamic2 branch November 19, 2024 13:48
JPryce-Aklundh added a commit to JPryce-Aklundh/docs-cypher that referenced this pull request Nov 19, 2024
Co-authored-by: Stefano Ottolenghi <[email protected]>
gem-neo4j pushed a commit to gem-neo4j/docs-cypher that referenced this pull request Nov 28, 2024
Co-authored-by: Stefano Ottolenghi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants