-
Notifications
You must be signed in to change notification settings - Fork 58
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
Add docs on dynamic properties #972
Add docs on dynamic properties #972
Conversation
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! I think there is a spelling misstake otherwise clear and well explained.
7b7ebfd
to
1bb0556
Compare
@JoelBergstrand I have added a new part for dynamic labels for SET/REMOVE now as well :D |
1bb0556
to
6eb3b4e
Compare
6eb3b4e
to
fe4cd12
Compare
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.
Thanks @gem-neo4j! There were a few queries here which I think may need more explanation (I have added suggestions to this end - let me know what you think 😸 )
WITH [k IN keys(n) WHERE k CONTAINS "Test" | k] as propertyKeys | ||
FOREACH (i IN propertyKeys | REMOVE k[i]) |
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.
See subsequent comment for context
WITH [k IN keys(n) WHERE k CONTAINS "Test" | k] as propertyKeys | |
FOREACH (i IN propertyKeys | REMOVE k[i]) | |
WITH [k IN keys(n) WHERE k CONTAINS "Test" | k] as propertyKeys // <1> | |
FOREACH (i IN propertyKeys | REMOVE k[i]) // <2> |
FOREACH (i IN propertyKeys | REMOVE k[i]) | ||
RETURN n.name, keys(n); | ||
---- | ||
|
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 this query needs a bit more explanation (though Im not sure my attempt is accurate 😄 )
<1> The xref:function/list.adoc#functions-key[keys()] function retrieves all property keys of the matched nodes, and a xref:values-and-types/lists.adoc#cypher-list-comprehension[list comprehension]filters these keys to include only those that contain the substring "Test", assigning the resulting list to the variable `propertyKeys`. | |
<2> The xref:clauses/foreach.adoc[`FOREACH`] clause iterates over each key in the `propertyKeys` list and removes the corresponding property using the `REMOVE` clause. |
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 guess we should be clear that it gets all the keys of the node (singular) it is operating on, it isn't getting the keys of all the matched nodes (plural), but otherwise I think this good.
Could even mention it removes the corresponding property dynamically 😏 hehe but that is probably obvious 😅
== Dynamically removing a label | ||
|
||
`REMOVE` can be used to remove a label on a node even when the label is not statically known. | ||
|
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 we add the relevant syntax here as well?
[source, cypher, indent=0] | ||
---- | ||
MATCH (n {name: 'Peter'}) | ||
UNWIND labels(n) AS 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.
UNWIND labels(n) AS label | |
UNWIND labels(n) AS label // <1> |
REMOVE n:$(label) | ||
RETURN n.name, labels(n) | ||
---- | ||
|
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.
<1> xref:clauses/unwind.adoc[`UNWIND`] is used here to transform the list of labels from the xref:functions/list.adoc#functions-list[`lists()]` function into separate rows, allowing subsequent operations to be performed on each label individually. |
modules/ROOT/pages/clauses/set.adoc
Outdated
[source, cypher] | ||
---- | ||
MATCH (n) | ||
FOREACH (k IN keys(n) | SET n[k + "Copy"] = n[k]) |
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.
FOREACH (k IN keys(n) | SET n[k + "Copy"] = n[k]) | |
FOREACH (k IN keys(n) | SET n[k + "Copy"] = n[k]) // <1> |
FOREACH (k IN keys(n) | SET n[k + "Copy"] = n[k]) | ||
RETURN n.name, keys(n); | ||
---- | ||
|
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.
<1> The xref:clauses/foreach.adoc#[`FOREACH`] clause iterates over each property key `k` obtained from the xref:function/list.adoc#functions-key[`keys()`] function. | |
For each key, it sets a new property on the nodes with a key name of `k` + "Copy" and copies the value from the original property. |
@@ -522,3 +585,28 @@ The newly-labeled node is returned by the query. | |||
2+d|Rows: 1 + | |||
Labels added: 2 | |||
|=== | |||
|
|||
[[set-set-multiple-dynamic-labels-on-a-node]] |
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.
[[set-set-multiple-dynamic-labels-on-a-node]] | |
[role=label--new-5.24] | |
[[set-set-multiple-dynamic-labels-on-a-node]] |
modules/ROOT/pages/clauses/set.adoc
Outdated
.Query | ||
[source, cypher] | ||
---- | ||
WITH COLLECT { UNWIND range(0,3) AS id RETURN "Label" + id } as 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.
WITH COLLECT { UNWIND range(0,3) AS id RETURN "Label" + id } as labels | |
WITH COLLECT { UNWIND range(0,3) AS id RETURN "Label" + id } as labels //<1> |
SET n:$(labels) | ||
RETURN n.name, labels(n) AS 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.
<1> A xref:subqueries/collect.adoc[`COLLECT`] subquery aggregates the results of `UNWIND range(0,3) AS id RETURN "Label" + id`, which generates a `LIST<STRING>` strings ("Label0", "Label1", "Label2", "Label3"), and assigns it to the variable `labels`. |
[source, cypher] | ||
---- | ||
MATCH (n:Swedish) | ||
SET n:$(n.name) |
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 we have an example where the label to add comes from a Cypher parameter, what would the syntax look like ?
SET n:$($label) ?
Same for multiple labels.
2da8a1d
to
d31e717
Compare
d31e717
to
1524325
Compare
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.
No additional comments from me.
Thanks for the documentation updates. The preview documentation has now been torn down - reopening this PR will republish it. |
No description provided.