Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion modules/ROOT/pages/subqueries/call-subquery.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ The variables returned in a subquery are available to the outer scope of the enc
In this example, the `CALL` subquery executes three times, one for each row that the xref:clauses/unwind.adoc[`UNWIND`] clause outputs.

.Query
// tag::subqueries_call_subquery_basic_example[]
[source, cypher]
----
UNWIND [0, 1, 2] AS x
Expand All @@ -58,6 +59,8 @@ CALL () {
}
RETURN innerReturn
----
// end::subqueries_call_subquery_basic_example[]


.Result
[role="queryresult",options="header,footer",cols="m"]
Expand Down Expand Up @@ -117,6 +120,7 @@ As a result, `CALL` subqueries can help maintain optimal performance and scalabi
In this example, a `CALL` subquery is used to xref:functions/aggregating.adoc#functions-collect[`collect`] a `LIST` containing all players who play for a particular team.

.Collect a list of all players playing for a particular team
// tag::subqueries_call_subquery_variable_scope[]
[source, cypher]
----
MATCH (t:Team)
Expand All @@ -126,6 +130,8 @@ CALL (t) {
}
RETURN t AS team, players
----
// end::subqueries_call_subquery_variable_scope[]


.Result
[source, role="queryresult",options="header,footer",cols="m,2m"]
Expand Down Expand Up @@ -457,6 +463,7 @@ RETURN p.name AS playerName, team.name AS team
Note that no results are returned for `Player C`, since they are not connected to any `Team` with a `PLAYS_FOR` relationship.

.Query using regular `OPTIONAL CALL`
// tag::subqueries_call_subquery_optional_call[]
[source, cypher]
----
MATCH (p:Player)
Expand All @@ -466,10 +473,10 @@ OPTIONAL CALL (p) {
}
RETURN p.name AS playerName, team.name AS team
----
// end::subqueries_call_subquery_optional_call[]

Now all `Player` nodes, regardless of whether they have any `PLAYS_FOR` relationships connected to a `Team`, are returned.

.Result
.Result
[role="queryresult",options="header,footer",cols="2*m"]
|===
Expand Down Expand Up @@ -572,6 +579,7 @@ Call subqueries can be used to further process the results of a xref:clauses/uni
This example query finds the youngest and the oldest `Player` in the graph.

.Find the oldest and youngest players
// tag::subqueries_call_subquery_optional_union[]
[source, cypher]
----
CALL () {
Expand All @@ -587,6 +595,7 @@ UNION
}
RETURN p.name AS playerName, p.age AS age
----
// end::subqueries_call_subquery_optional_union[]

.Result
[role="queryresult",options="header,footer",cols="2*<m"]
Expand Down
13 changes: 13 additions & 0 deletions modules/ROOT/pages/subqueries/subqueries-in-transactions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ It creates nodes in separate transactions using `CALL { ... } IN TRANSACTIONS`:
----

.Query
// tag::subqueries_in_transactions_basic_example[]
[source, cypher]
----
LOAD CSV FROM 'file:///friends.csv' AS line
CALL (line) {
CREATE (:Person {name: line[1], age: toInteger(line[2])})
} IN TRANSACTIONS
----
// end::subqueries_in_transactions_basic_example[]


.Result
[role="queryresult",options="footer",cols="1*<m"]
Expand Down Expand Up @@ -155,13 +158,15 @@ This example loads a CSV file with one transaction for every `2` input rows:
----

.Query
// tag::subqueries_in_transactions_batching[]
[source, cypher]
----
LOAD CSV FROM 'file:///friends.csv' AS line
CALL (line) {
CREATE (:Person {name: line[1], age: toInteger(line[2])})
} IN TRANSACTIONS OF 2 ROWS
----
// end::subqueries_in_transactions_batching[]

.Result
[role="queryresult",options="footer",cols="1*<m"]
Expand Down Expand Up @@ -372,6 +377,7 @@ RETURN e.num
In the following example, `ON ERROR CONTINUE` is used after a failed inner transaction to execute the remaining inner transactions and not fail the outer transaction:

.Transactions batched in 1 row with `ON ERROR CONTINUE`
// tag::subqueries_in_transactions_error_behavior[]
[source, cypher]
----
UNWIND [1, 0, 2, 4] AS i
Expand All @@ -383,6 +389,8 @@ CALL (i) {
ON ERROR CONTINUE
RETURN n.num
----
// end::subqueries_in_transactions_error_behavior[]


.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down Expand Up @@ -791,6 +799,8 @@ If a negative number is specified (which can only be done through a parameter),
`CALL { ... } IN CONCURRENT TRANSACTIONS` is particularly suitable for importing data without dependencies.
This example creates `Person` nodes from a unique `tmdbId` value assigned to each person row in the CSV file (444 in total) in 3 concurrent transactions.

.`CALL` subquery run in `CONCURRENT TRANSACTIONS`
// tag::subqueries_in_transactions_concurrent_transactions[]
[source, cypher]
----
LOAD CSV WITH HEADERS FROM 'https://data.neo4j.com/importing-cypher/persons.csv' AS row
Expand All @@ -800,6 +810,7 @@ CALL (row) {
} IN 3 CONCURRENT TRANSACTIONS OF 10 ROWS
RETURN count(*) AS personNodes
----
// end::subqueries_in_transactions_concurrent_transactions[]

.Result
[role="queryresult",options="header,footer",cols="m"]
Expand Down Expand Up @@ -939,6 +950,7 @@ To retry the any failed inner transactions, use the error option `ON ERROR RETRY
The following query uses `ON ERROR RETRY ... THEN CONTINUE` to retry the above query for a maximum of `3` seconds and then continue the execution of subsequent inner transactions by ignoring any recoverable errors.

.Query using `ON ERROR RETRY ... THEN CONTINUE` to retry deadlocked inner transactions and complete outer transaction
// tag::subqueries_in_transactions_deadlock_example[]
[source, cypher]
----
LOAD CSV WITH HEADERS FROM 'https://data.neo4j.com/importing-cypher/movies.csv' AS row
Expand All @@ -949,6 +961,7 @@ CALL (row) {
} IN 2 CONCURRENT TRANSACTIONS OF 10 ROWS ON ERROR RETRY FOR 3 SECONDS THEN CONTINUE REPORT STATUS AS status
RETURN status.transactionID as transaction, status.committed AS successfulTransaction
----
// end::subqueries_in_transactions_deadlock_example[]

The result shows that all transactions are now successful:

Expand Down