From c191b2331eb89891365bf1cd5a78c30788366046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Fri, 11 Apr 2025 14:50:50 +0200 Subject: [PATCH 1/6] initial --- .../expressions/graph-element-operators.adoc | 65 ++++++ modules/ROOT/pages/expressions/index.adoc | 5 +- modules/ROOT/pages/syntax/operators.adoc | 186 ------------------ 3 files changed, 69 insertions(+), 187 deletions(-) create mode 100644 modules/ROOT/pages/expressions/graph-element-operators.adoc delete mode 100644 modules/ROOT/pages/syntax/operators.adoc diff --git a/modules/ROOT/pages/expressions/graph-element-operators.adoc b/modules/ROOT/pages/expressions/graph-element-operators.adoc new file mode 100644 index 000000000..dd82290fe --- /dev/null +++ b/modules/ROOT/pages/expressions/graph-element-operators.adoc @@ -0,0 +1,65 @@ += Property operators +:description: Information about Cypher's graph element operators, which enable the querying and manipulation of nodes and relationships. + +Property operators allow you to manipulate and query `NODE` and `RELATIONSHIP` values. +Cypher contains the following graph element operators: + +* Static property access: dot operator (`.`) +* Dynamic property access: subscript operator (`[]`) + +For functions that return metadata about `NODE` and `RELATIONSHIPS` values, see: + +* xref:functions/scalar.adoc#functions-elementid[`elementId()`] +* xref:functions/scalar.adoc#functions-endnode[`endNode()`] +* xref:functions/scalar.adoc#functions-id[`id()`] +* xref:functions/list.adoc#functions-keys[`keys()`] +* xref:functions/list.adoc#functions-labels[`labels()`] +* xref:functions/scalar.adoc#functions-properties[`properties()`] +* xref:functions/scalar.adoc#functions-startnode[`startNode()`] +* xref:functions/scalar.adoc#functions-type[`type()`] + + +== Example graph + +CREATE (alice:Person {name:'Alice', age: 65, role: 'Project manager', skills: ['Java', 'Python']}), + (cecil:Person {name: 'Cecil', age: 25, role: 'Software developer', skills: ['Java', 'Python']}), + (cecilia:Person {name: 'Cecilia', age: 31, role: 'Software developer', skills: ['JavaScript', 'TypeScript']}), + (charlie:Person {name: 'Charlie', age: 61, role: 'Security engineer', skills: ['C++', 'Python']}), + (daniel:Person {name: 'Daniel', age: 39, role: 'Director', skills: ['Ruby', 'Go']}), + (eskil:Person {name: 'Eskil', age: 39, role: 'CEO'}), + + (cecil)-[:WORKS_FOR {since: date('2022-01-01')}]->(alice), + (cecilia)-[:WORKS_FOR {since: date('2020-10-15')}]->(alice), + (charlie)-[:WORKS_FOR {since: date('2009-11-08')}]->(daniel), + (alice)-[:WORKS_FOR]->(daniel), + (daniel)-[:WORKS_FOR]->(eskil) + +== Static property access + +Property values can be accessed statically by specifying a property name after the `.` operator. + +MATCH (p:Person) +RETURN p.name + +MATCH (:Person)-[r:WORKS_FOR]-(:Person) +RETURN r.since + + +== Dynamic property access + +Property values can be accessed dynamically by using the subscript operator, `[]`. + +LET nodeProperty = 'name' +MATCH (:Person) +RETURN p[propertyName] AS + + + + + + + + + + +== Dynamic property access \ No newline at end of file diff --git a/modules/ROOT/pages/expressions/index.adoc b/modules/ROOT/pages/expressions/index.adoc index 5a05fe28f..75471bd86 100644 --- a/modules/ROOT/pages/expressions/index.adoc +++ b/modules/ROOT/pages/expressions/index.adoc @@ -1,9 +1,13 @@ = Expressions +:description: Information about the expressions available in Cypher. +:page-aliases: syntax/operators.adoc + A Cypher expression is any part of a query that evaluates to a value. For details and examples of specific expressions, see the following sections: * xref:expressions/expressions-overview.adoc[] +* xref:expressions/property-operators.adoc[] * xref:expressions/predicates/index.adoc[] ** xref:expressions/predicates/boolean-operators.adoc[]: `AND`, `OR`, `XOR`, `NOT` ** xref:expressions/predicates/comparison-operators.adoc[]: `=`, `<>`, `<`, `>`, `\<=`, `>=`, `IS NULL`, `IS NOT NULL` @@ -17,4 +21,3 @@ For details and examples of specific expressions, see the following sections: * xref:expressions/list-expressions.adoc[]: information about list concatenation operators (`||`, `+`), list element access, list slicing, and list as well as pattern comprehensions. * xref:expressions/map-expressions.adoc[]: information about map operators (`.`, `[]`) and map projection. * xref:expressions/conditional-expressions.adoc[] - diff --git a/modules/ROOT/pages/syntax/operators.adoc b/modules/ROOT/pages/syntax/operators.adoc deleted file mode 100644 index a58738415..000000000 --- a/modules/ROOT/pages/syntax/operators.adoc +++ /dev/null @@ -1,186 +0,0 @@ -:description: This section contains an overview of operators. -[[query-operators]] -= Operators - -This page contains an overview of the available Cypher operators. - -[[query-operators-summary]] -== Operators at a glance - -[subs=none] -|=== -| xref::syntax/operators.adoc#query-operators-aggregation[Aggregation operators] | `DISTINCT` -| xref::syntax/operators.adoc#query-operators-property[Property operators] | `.` for static property access, `[]` for dynamic property access, `=` for replacing all properties, `+=` for mutating specific properties -|=== - -[[query-operators-aggregation]] -== Aggregation operators - -The aggregation operators comprise: - -* remove duplicates values: `DISTINCT` - -[[syntax-using-the-distinct-operator]] -=== Using the `DISTINCT` operator - -Retrieve the unique eye colors from `Person` nodes. - -.Query -[source, cypher] ----- -CREATE - (a:Person {name: 'Anne', eyeColor: 'blue'}), - (b:Person {name: 'Bill', eyeColor: 'brown'}), - (c:Person {name: 'Carol', eyeColor: 'blue'}) -WITH [a, b, c] AS ps -UNWIND ps AS p -RETURN DISTINCT p.eyeColor ----- - -Even though both *'Anne'* and *'Carol'* have blue eyes, *'blue'* is only returned once. - -.Result -[role="queryresult",options="header,footer",cols="1* 6 -RETURN DISTINCT restaurant.name ----- - -.Result -[role="queryresult",options="header,footer",cols="1* Filter on dynamic properties]. - -[NOTE] -==== -The behavior of the `[]` operator with respect to `null` is detailed xref::values-and-types/working-with-null.adoc#cypher-null-bracket-operator[here]. -==== - - -[[syntax-property-replacement-operator]] -=== Replacing all properties of a node or relationship using the `=` operator - -.Query -[source, cypher] ----- -CREATE (a:Person {name: 'Sofia', age: 20}) -WITH a -MATCH (p:Person {name: 'Sofia'}) -SET p = {name: 'Ellen', livesIn: 'London'} -RETURN p.name, p.age, p.livesIn ----- - -All the existing properties on the node are replaced by those provided in the map; i.e. the `name` property is updated from `Sofia` to `Ellen`, the `age` property is deleted, and the `livesIn` property is added. - -.Result -[role="queryresult",options="header,footer",cols="3*+ | +"London"+ - -3+d|Rows: 1 -|=== - -See xref::clauses/set.adoc#set-replace-properties-using-map[Replace all properties using a map and `=`] for more details on using the property replacement operator `=`. - - -[[syntax-property-mutation-operator]] -=== Mutating specific properties of a node or relationship using the `+=` operator - -.Query -[source, cypher] ----- -CREATE (a:Person {name: 'Sofia', age: 20}) -WITH a -MATCH (p:Person {name: 'Sofia'}) -SET p += {name: 'Ellen', livesIn: 'London'} -RETURN p.name, p.age, p.livesIn ----- - -The properties on the node are updated as follows by those provided in the map: the `name` property is updated from `Sofia` to `Ellen`, the `age` property is left untouched, and the `livesIn` property is added. - -.Result -[role="queryresult",options="header,footer",cols="3* Date: Mon, 14 Apr 2025 14:38:45 +0200 Subject: [PATCH 2/6] more --- modules/ROOT/content-nav.adoc | 1 + .../expressions/graph-element-operators.adoc | 158 +++++++++++++++--- modules/ROOT/pages/expressions/index.adoc | 2 +- 3 files changed, 139 insertions(+), 22 deletions(-) diff --git a/modules/ROOT/content-nav.adoc b/modules/ROOT/content-nav.adoc index 223b28d68..07c257fa2 100644 --- a/modules/ROOT/content-nav.adoc +++ b/modules/ROOT/content-nav.adoc @@ -73,6 +73,7 @@ *** xref:expressions/predicates/string-operators.adoc[] *** xref:expressions/predicates/path-pattern-expressions.adoc[] *** xref:expressions/predicates/type-predicate-expressions.adoc[] +** xref:expressions/graph-element-operators.adoc[] ** xref:expressions/mathematical-operators.adoc[] ** xref:expressions/string-operators.adoc[] ** xref:expressions/temporal-operators.adoc[] diff --git a/modules/ROOT/pages/expressions/graph-element-operators.adoc b/modules/ROOT/pages/expressions/graph-element-operators.adoc index dd82290fe..6e158dc1d 100644 --- a/modules/ROOT/pages/expressions/graph-element-operators.adoc +++ b/modules/ROOT/pages/expressions/graph-element-operators.adoc @@ -1,7 +1,7 @@ -= Property operators += Graph element operators :description: Information about Cypher's graph element operators, which enable the querying and manipulation of nodes and relationships. -Property operators allow you to manipulate and query `NODE` and `RELATIONSHIP` values. +Graph element operators allow you to manipulate and query `NODE` and `RELATIONSHIP` property values. Cypher contains the following graph element operators: * Static property access: dot operator (`.`) @@ -19,47 +19,163 @@ For functions that return metadata about `NODE` and `RELATIONSHIPS` values, see: * xref:functions/scalar.adoc#functions-type[`type()`] +[[example-graph]] == Example graph -CREATE (alice:Person {name:'Alice', age: 65, role: 'Project manager', skills: ['Java', 'Python']}), - (cecil:Person {name: 'Cecil', age: 25, role: 'Software developer', skills: ['Java', 'Python']}), - (cecilia:Person {name: 'Cecilia', age: 31, role: 'Software developer', skills: ['JavaScript', 'TypeScript']}), - (charlie:Person {name: 'Charlie', age: 61, role: 'Security engineer', skills: ['C++', 'Python']}), - (daniel:Person {name: 'Daniel', age: 39, role: 'Director', skills: ['Ruby', 'Go']}), - (eskil:Person {name: 'Eskil', age: 39, role: 'CEO'}), +The following graph is used for the examples below: - (cecil)-[:WORKS_FOR {since: date('2022-01-01')}]->(alice), - (cecilia)-[:WORKS_FOR {since: date('2020-10-15')}]->(alice), - (charlie)-[:WORKS_FOR {since: date('2009-11-08')}]->(daniel), - (alice)-[:WORKS_FOR]->(daniel), - (daniel)-[:WORKS_FOR]->(eskil) +To recreate the graph, run the following query against an empty Neo4j database: +[source, cypher, role=test-setup] +---- +CREATE (alice:Person {firstName:'Alice', middleName: 'Catherine', lastName: 'Baxter'}), + (cecil:Person {firstName: 'Cecil', middleName: 'David', lastName: 'Ericson'}), + (cecilia:Person {firstName: 'Cecilia', lastName: 'Farega'}), + (cecil)-[:WORKS_FOR {since: 2023}]->(alice), + (cecilia)-[:WORKS_FOR {since: 2015}]->(alice) +---- + +[[static-property-access]] == Static property access Property values can be accessed statically by specifying a property name after the `.` operator. +.Access node properties statically +[source, cypher] +---- +MATCH (p:Person) +RETURN p.firstName AS name +---- + +.Result +[role="queryresult",options="header,footer",cols="1*`, `<`, `>`, `\<=`, `>=`, `IS NULL`, `IS NOT NULL` @@ -15,6 +14,7 @@ For details and examples of specific expressions, see the following sections: ** xref:expressions/predicates/string-operators.adoc[]: `STARTS WITH`, `ENDS WITH`, `CONTAINS`, `IS NORMALIZED`, `IS NOT NORMALIZED`, `=~` ** xref:expressions/predicates/path-pattern-expressions.adoc[]: information about filtering queries with path pattern expressions. ** xref:expressions/predicates/type-predicate-expressions.adoc[]: information about how to verify the value type of a Cypher expression. +* xref:expressions/graph-element-operators.adoc[]: `.`, `[]` * xref:expressions/mathematical-operators.adoc[]: `+`, `-`, `*`, `/`, `%`, `^`. * xref:expressions/string-operators.adoc[]: `+`, `||` * xref:expressions/temporal-operators.adoc[]: `+`, `-`, `*`, `/` From b3872153f00f1dbda07f707f00d6f85615b32a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Mon, 14 Apr 2025 14:40:27 +0200 Subject: [PATCH 3/6] index update --- modules/ROOT/pages/expressions/index.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ROOT/pages/expressions/index.adoc b/modules/ROOT/pages/expressions/index.adoc index fcb5c454d..89e9ce37f 100644 --- a/modules/ROOT/pages/expressions/index.adoc +++ b/modules/ROOT/pages/expressions/index.adoc @@ -14,7 +14,7 @@ For details and examples of specific expressions, see the following sections: ** xref:expressions/predicates/string-operators.adoc[]: `STARTS WITH`, `ENDS WITH`, `CONTAINS`, `IS NORMALIZED`, `IS NOT NORMALIZED`, `=~` ** xref:expressions/predicates/path-pattern-expressions.adoc[]: information about filtering queries with path pattern expressions. ** xref:expressions/predicates/type-predicate-expressions.adoc[]: information about how to verify the value type of a Cypher expression. -* xref:expressions/graph-element-operators.adoc[]: `.`, `[]` +* xref:expressions/graph-element-operators.adoc[]: information about how to access property values with `.` and `[]`. * xref:expressions/mathematical-operators.adoc[]: `+`, `-`, `*`, `/`, `%`, `^`. * xref:expressions/string-operators.adoc[]: `+`, `||` * xref:expressions/temporal-operators.adoc[]: `+`, `-`, `*`, `/` From 57b2d54dce8717bec3712ce1c2ef7d5e1d1e541d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Mon, 14 Apr 2025 14:50:00 +0200 Subject: [PATCH 4/6] add graph --- modules/ROOT/images/graph_element_operators.svg | 1 + modules/ROOT/pages/expressions/graph-element-operators.adoc | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 modules/ROOT/images/graph_element_operators.svg diff --git a/modules/ROOT/images/graph_element_operators.svg b/modules/ROOT/images/graph_element_operators.svg new file mode 100644 index 000000000..1617bf92f --- /dev/null +++ b/modules/ROOT/images/graph_element_operators.svg @@ -0,0 +1 @@ +WORKS_FORsince:2023WORKS_FORsince:2015PersonfirstName:'Cecil'middleName:'David'lastName:'Ericson'PersonfirstName:'Cecilia'lastName:'Farega'PersonfirstName:'Alice'middleName:'Catherine'lastName:'Baxter' \ No newline at end of file diff --git a/modules/ROOT/pages/expressions/graph-element-operators.adoc b/modules/ROOT/pages/expressions/graph-element-operators.adoc index 6e158dc1d..726ead533 100644 --- a/modules/ROOT/pages/expressions/graph-element-operators.adoc +++ b/modules/ROOT/pages/expressions/graph-element-operators.adoc @@ -24,6 +24,8 @@ For functions that return metadata about `NODE` and `RELATIONSHIPS` values, see: The following graph is used for the examples below: +image::graph_element_operators.svg[width="600",role="middle"] + To recreate the graph, run the following query against an empty Neo4j database: [source, cypher, role=test-setup] @@ -123,7 +125,7 @@ RETURN p[$propertyName] AS middleName .Result [role="queryresult",options="header,footer",cols="1* Date: Mon, 14 Apr 2025 14:58:16 +0200 Subject: [PATCH 5/6] rephrase --- modules/ROOT/pages/expressions/graph-element-operators.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ROOT/pages/expressions/graph-element-operators.adoc b/modules/ROOT/pages/expressions/graph-element-operators.adoc index 726ead533..6a4d78ad3 100644 --- a/modules/ROOT/pages/expressions/graph-element-operators.adoc +++ b/modules/ROOT/pages/expressions/graph-element-operators.adoc @@ -136,8 +136,8 @@ RETURN p[$propertyName] AS middleName == Handling `NULL` values -If a property (or property value) is missing in an expression using a graph element operator, the whole expression will evaluate to `NULL`. -The below query performs a xref:expressions/string-operators.adoc[string concatentation] on the `firstName`, `middleName`, and `lastName` properties on `Person` nodes. +If a property (or property value) is missing in an expression that uses a graph element operator, the whole expression will evaluate to `NULL`. +The query below performs a xref:expressions/string-operators.adoc[string concatentation] on the `firstName`, `middleName`, and `lastName` properties on `Person` nodes. Note that `NULL` is returned for `Cecilia`, who lacks a `middleName` property. .String concatenation using node properties From 37db3c374f2482757cd06bacc757359fe12bea3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Mon, 14 Apr 2025 16:38:51 +0200 Subject: [PATCH 6/6] rename --- modules/ROOT/content-nav.adoc | 2 +- modules/ROOT/pages/expressions/index.adoc | 2 +- ...erators.adoc => node-relationship-operators.adoc} | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) rename modules/ROOT/pages/expressions/{graph-element-operators.adoc => node-relationship-operators.adoc} (89%) diff --git a/modules/ROOT/content-nav.adoc b/modules/ROOT/content-nav.adoc index 07c257fa2..1f2ddf6d0 100644 --- a/modules/ROOT/content-nav.adoc +++ b/modules/ROOT/content-nav.adoc @@ -73,7 +73,7 @@ *** xref:expressions/predicates/string-operators.adoc[] *** xref:expressions/predicates/path-pattern-expressions.adoc[] *** xref:expressions/predicates/type-predicate-expressions.adoc[] -** xref:expressions/graph-element-operators.adoc[] +** xref:expressions/node-relationship-operators.adoc[] ** xref:expressions/mathematical-operators.adoc[] ** xref:expressions/string-operators.adoc[] ** xref:expressions/temporal-operators.adoc[] diff --git a/modules/ROOT/pages/expressions/index.adoc b/modules/ROOT/pages/expressions/index.adoc index 89e9ce37f..df1119866 100644 --- a/modules/ROOT/pages/expressions/index.adoc +++ b/modules/ROOT/pages/expressions/index.adoc @@ -14,7 +14,7 @@ For details and examples of specific expressions, see the following sections: ** xref:expressions/predicates/string-operators.adoc[]: `STARTS WITH`, `ENDS WITH`, `CONTAINS`, `IS NORMALIZED`, `IS NOT NORMALIZED`, `=~` ** xref:expressions/predicates/path-pattern-expressions.adoc[]: information about filtering queries with path pattern expressions. ** xref:expressions/predicates/type-predicate-expressions.adoc[]: information about how to verify the value type of a Cypher expression. -* xref:expressions/graph-element-operators.adoc[]: information about how to access property values with `.` and `[]`. +* xref:expressions/node-relationship-operators.adoc[]: information about how to access `NODE` and `RELATIONSHIP` property values with `.` and `[]`. * xref:expressions/mathematical-operators.adoc[]: `+`, `-`, `*`, `/`, `%`, `^`. * xref:expressions/string-operators.adoc[]: `+`, `||` * xref:expressions/temporal-operators.adoc[]: `+`, `-`, `*`, `/` diff --git a/modules/ROOT/pages/expressions/graph-element-operators.adoc b/modules/ROOT/pages/expressions/node-relationship-operators.adoc similarity index 89% rename from modules/ROOT/pages/expressions/graph-element-operators.adoc rename to modules/ROOT/pages/expressions/node-relationship-operators.adoc index 6a4d78ad3..65dc5a1bc 100644 --- a/modules/ROOT/pages/expressions/graph-element-operators.adoc +++ b/modules/ROOT/pages/expressions/node-relationship-operators.adoc @@ -1,13 +1,13 @@ -= Graph element operators -:description: Information about Cypher's graph element operators, which enable the querying and manipulation of nodes and relationships. += Node and relationship operators +:description: Information about Cypher's node and relationship operators, which enable the querying and manipulation of nodes and relationships. -Graph element operators allow you to manipulate and query `NODE` and `RELATIONSHIP` property values. -Cypher contains the following graph element operators: +Node and relationship operators allow you to manipulate and query `NODE` and `RELATIONSHIP` property values. +Cypher contains the following node and relationship operators: * Static property access: dot operator (`.`) * Dynamic property access: subscript operator (`[]`) -For functions that return metadata about `NODE` and `RELATIONSHIPS` values, see: +For functions that return metadata about `NODE` and `RELATIONSHIP` values, see: * xref:functions/scalar.adoc#functions-elementid[`elementId()`] * xref:functions/scalar.adoc#functions-endnode[`endNode()`] @@ -136,7 +136,7 @@ RETURN p[$propertyName] AS middleName == Handling `NULL` values -If a property (or property value) is missing in an expression that uses a graph element operator, the whole expression will evaluate to `NULL`. +If a property (or property value) is missing in an expression that uses tries to access a property statically or dynamically, the whole expression will evaluate to `NULL`. The query below performs a xref:expressions/string-operators.adoc[string concatentation] on the `firstName`, `middleName`, and `lastName` properties on `Person` nodes. Note that `NULL` is returned for `Cecilia`, who lacks a `middleName` property.