Skip to content

Commit

Permalink
Merge branch 'dev' into cheat_sheet_patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
JPryce-Aklundh authored Dec 3, 2024
2 parents 33a7adf + 76cc351 commit 303e96f
Show file tree
Hide file tree
Showing 13 changed files with 2,586 additions and 2,645 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ REMOVE n:$($label)
| Description

| xref:functions/graph.adoc#functions-graph-by-elementid[`graph.byElementId()`]
| Returns the graph reference with the given element id. It is only supported in the `USE` clause, on composite databases.
| Returns the graph reference with the given element id.
It is only supported in the xref:clauses/use.adoc[`USE`] clause.
As of Neo4j 5.26, it is supported on both link:{neo4j-docs-base-uri}/operations-manual/{page-version}/database-administration/[standard and composite databases].
On earlier versions, it is only supported on composite databases.

| xref:functions/graph.adoc#functions-graph-byname[`graph.byName()`]
| Returns the graph reference of the given name. It is only supported in the `USE` clause, on composite databases.
Expand Down
2 changes: 2 additions & 0 deletions modules/ROOT/pages/clauses/create.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ This is because a relationship can only have exactly one type.
----

.Create nodes and relationships using dynamic node labels and relationship types
// tag::clauses_create_dynamic_create[]
[source, cypher]
----
CREATE (greta:$($nodeLabels) {name: 'Greta Gerwig'})
Expand All @@ -243,6 +244,7 @@ UNWIND $movies AS movieTitle
CREATE (greta)-[rel:$($relType)]->(m:Movie {title: movieTitle})
RETURN greta.name AS name, labels(greta) AS labels, type(rel) AS relType, collect(m.title) AS movies
----
// end::clauses_create_dynamic_create[]

.Result
[role="queryresult",options="footer",cols="4*<m"]
Expand Down
6 changes: 4 additions & 2 deletions modules/ROOT/pages/clauses/load-csv.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ It also mitigates the risk of Cypher injection.
(For more information about Cypher injection, see link:https://neo4j.com/developer/kb/protecting-against-cypher-injection/[Neo4j Knowledge Base -> Protecting against Cypher injection]).

.bands-with-headers.csv
[source, csv, filename="artists-with-headers.csv"]
[source, csv, filename="bands-with-headers.csv"]
----
Id,Label,Name
1,Band,The Beatles
Expand All @@ -319,12 +319,14 @@ Id,Label,Name
----

.Query
[source, cypher, role=test-skip]
// tag::clauses_load_csv_dynamic_columns[]
[source, cypher]
----
LOAD CSV WITH HEADERS FROM 'file:///bands-with-headers.csv' AS line
MERGE (n:$(line.Label) {name: line.Name})
RETURN n AS bandNodes
----
// end::clauses_load_csv_dynamic_columns[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down
8 changes: 7 additions & 1 deletion modules/ROOT/pages/clauses/match.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ RETURN directors
1+d|Rows: 2
|===

.Match nodes dynamically using the `any()` function
.Match nodes dynamically using `any()`
[source, cypher]
----
MATCH (n:$any(["Movie", "Actor"]))
Expand Down Expand Up @@ -586,11 +586,14 @@ RETURN n AS nodes
----

.Match nodes dynamically using a parameter
// tag::clauses_match_dynamic_match_parameter[]
[source, cypher]
----
MATCH (movie:$($label))
RETURN movie.title AS movieTitle
----
// end::clauses_match_dynamic_match_parameter[]


.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand All @@ -605,13 +608,16 @@ RETURN movie.title AS movieTitle


.Match relationships dynamically using a variable
// tag::clauses_match_dynamic_match_variable[]
[source, cypher]
----
CALL db.relationshipTypes()
YIELD relationshipType
MATCH ()-[r:$(relationshipType)]->()
RETURN relationshipType, count(r) AS relationshipCount
----
// end::clauses_match_dynamic_match_variable[]


.Result
[role="queryresult",options="header,footer",cols="2*<m"]
Expand Down
2 changes: 2 additions & 0 deletions modules/ROOT/pages/clauses/merge.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ This is because the xref:planning-and-tuning/execution-plans.adoc[Cypher planner
----

.Merge nodes and relationships using dynamic node labels and relationship types
// tag::clauses_merge_dynamic_merge[]
[source, cypher]
----
MERGE (greta:$($nodeLabels) {name: 'Greta Gerwig'})
Expand All @@ -726,6 +727,7 @@ UNWIND $movies AS movieTitle
MERGE (greta)-[rel:$($relType)]->(m:Movie {title: movieTitle})
RETURN greta.name AS name, labels(greta) AS labels, type(rel) AS relType, collect(m.title) AS movies
----
// end::clauses_merge_dynamic_merge[]

.Result
[role="queryresult",options="footer",cols="3*<m"]
Expand Down
14 changes: 10 additions & 4 deletions modules/ROOT/pages/clauses/use.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ MATCH (n) RETURN n
[[query-use-examples-query-composite-database-constituent-graph-dynamically]]
=== Query a composite database constituent graph dynamically

The built-in function `graph.byName()` can be used in the `USE` clause to resolve a constituent graph from a `STRING` value containing the qualified name of a constituent.
The xref:functions/graph.adoc#functions-graph-byname[`graph.byName()`] function can be used in the `USE` clause to resolve a constituent graph from a `STRING` value containing the qualified name of a constituent.

This example uses a composite database named `myComposite` that includes an alias named `myConstituent`:

Expand All @@ -114,12 +114,18 @@ USE graph.byName($graphName)
MATCH (n) RETURN n
----

[role=label--new-5.13]
[[query-use-examples-query-composite-database-by-element-id]]
=== Query a composite database constituent using elementId

The `graph.byElementId()` function (introduced in Neo4j 5.13), can be used in the `USE` clause to resolve a constituent graph to which a given element id belongs.
In the below example, it is assumed that the DBMS contains a composite database constituent, which contains the element id `4:c0a65d96-4993-4b0c-b036-e7ebd9174905:0`.
If the constituent database is not a standard database in the DBMS an error will be thrown:
The xref:functions/graph.adoc#functions-graph-by-elementid[`graph.byElementId()`] function can be used in the `USE` clause to resolve a constituent graph to which a given xref:functions/scalar.adoc#functions-elementid[element id] belongs.
As of Neo4j 5.26, it is supported on both standard and composite databases (on previous versions it is only available on composite databases).

[NOTE]
On a standard database, a `USE` clause with `graph.byElementId()` cannot be combined with other `USE` clauses unless the subsequent `USE` clauses reference the same element id.

In the below example, it is assumed that the DBMS contains the database corresponding to the given element id. If you are connected to a composite database it needs to be a element id to a constituent database, which is a standard database in the DBMS.

.Query
[source, cypher, role=test-skip]
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ For more information on the deprecation of these formats, see link:{neo4j-docs-b
| Feature
| Details

a|
label:functionality[]
label:updated[]
[source, cypher, role="noheader"]
----
USE graph.byElementId("4:c0a65d96-4993-4b0c-b036-e7ebd9174905:0")
MATCH (n) RETURN n
----

| xref:functions/graph.adoc#functions-graph-by-elementid[`graph.byElementId()`] can now be used on both link:{neo4j-docs-base-uri}/operations-manual/{page-version}/database-administration/[standard and composite databases].
Previously it could only be used on composite databases.

a|
label:functionality[]
label:updated[]
Expand All @@ -181,6 +193,28 @@ label:updated[]
GRANT READ {*} ON GRAPH * FOR (n) WHERE n.createdAt > date('2024-10-25') TO regularUsers
----
| link:{neo4j-docs-base-uri}/operations-manual/{page-version}/authentication-authorization/property-based-access-control/[Property-based access control] now supports xref:values-and-types/spatial.adoc[spatial] and xref:values-and-types/temporal.adoc[temporal] values.


a|
label:functionality[]
label:updated[]
[source, cypher, role="noheader"]
----
RETURN 'val' as one, 'val' as two
UNION
RETURN 'val' as two, 'val' as one
----

[source, cypher, role="noheader"]
----
RETURN 'val' as one, 'val' as two
UNION ALL
RETURN 'val' as two, 'val' as one
----
a|

Using differently ordered return items in a `UNION [ALL]` clause has been un-deprecated.

|===


Expand Down
14 changes: 12 additions & 2 deletions modules/ROOT/pages/functions/graph.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,18 @@ For more information, see xref:subqueries/call-subquery.adoc#import-variables[CA
.Details
|===
| *Syntax* 3+| `graph.byName(name)`
| *Description* 3+| Returns the graph reference of the given name. It is only supported in the `USE` clause, on composite databases.
| *Description* 3+| Returns the graph reference of the given name.
.2+| *Arguments* | *Name* | *Type* | *Description*
| `name` | `STRING` | The name of the graph to be resolved.
| *Returns* 3+| `GRAPH`
|===


.Considerations
|===
| `graph.byName()` is only supported in the xref:clauses/use.adoc[`USE`] clause, on composite databases.
|===

.+graph.byName()+
======
Expand Down Expand Up @@ -183,7 +189,7 @@ For more information, see xref:subqueries/call-subquery.adoc#import-variables[CA
.Details
|===
| *Syntax* 3+| `graph.byElementId(elementId)`
| *Description* 3+| Returns the graph reference with the given element id. It is only supported in the `USE` clause, on composite databases.
| *Description* 3+| Returns the graph reference with the given element id.
.2+| *Arguments* | *Name* | *Type* | *Description*
| `elementId` | `STRING` | An element id of a node or relationship.
| *Returns* 3+| `GRAPH`
Expand All @@ -192,6 +198,10 @@ For more information, see xref:subqueries/call-subquery.adoc#import-variables[CA
.Considerations
|===
| If the constituent database is not a standard database in the DBMS, an error will be thrown.
| `graph.byElementId()` is only supported in the xref:clauses/use.adoc[`USE`] clause.
| As of Neo4j 5.26, `graph.byElementId()` is supported on both link:{neo4j-docs-base-uri}/operations-manual/{page-version}/database-administration/[standard and composite databases].
On earlier versions, it is only supported on composite databases.
| On a standard database, a `USE` clause with `graph.byElementId()` cannot be combined with other `USE` clauses unless the subsequent `USE` clauses reference the same element id.
|===

.+graph.byElementId()+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ image::patterns_qpp_solutions.svg[width="700",role="middle"]

For the purposes of understanding Cypher execution plans, however, the query result is less interesting than the planning that produces it.

[[runtimes-reading-execution-plans]]
[[reading-execution-plans]]
== Reading execution plans

The Cypher planner produces logical plans which describe how a particular query is going to be executed.
Expand Down
Loading

0 comments on commit 303e96f

Please sign in to comment.