From 57c17e1c2b640e9fad24d62c63722b579e9d98d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Mon, 30 Jan 2023 08:57:59 +0100 Subject: [PATCH 1/2] Update CALL subquery examples for testing (#348) --- modules/ROOT/pages/clauses/call-subquery.adoc | 183 +++++++++--------- 1 file changed, 89 insertions(+), 94 deletions(-) diff --git a/modules/ROOT/pages/clauses/call-subquery.adoc b/modules/ROOT/pages/clauses/call-subquery.adoc index 3e15b6631..34dd53746 100644 --- a/modules/ROOT/pages/clauses/call-subquery.adoc +++ b/modules/ROOT/pages/clauses/call-subquery.adoc @@ -36,7 +36,10 @@ The following graph is used for the examples below: image:graph_call_subquery_clause.svg[] -//// +To recreate the graph, run the following query in an empty Neo4j database: + +[source, cypher, role=test-setup] +---- CREATE (a:Person:Child {age: 20, name: 'Alice'}), (b:Person {age: 27, name: 'Bob'}), @@ -45,7 +48,7 @@ CREATE CREATE (a)-[:FRIEND_OF]->(b) CREATE (a)-[:CHILD_OF]->(c) CREATE (:Counter {count: 0}) -//// +---- [[call-semantics]] @@ -54,13 +57,13 @@ CREATE (:Counter {count: 0}) A `CALL` clause is executed once for each incoming row. -.Execute for each incomming row +.Execute for each incoming row ====== The `CALL` clause executes three times, one for each row that the `UNWIND` clause outputs. .Query -[source, cypher, role="noplay"] +[source, cypher] ---- UNWIND [0, 1, 2] AS x CALL { @@ -70,22 +73,16 @@ RETURN innerReturn ---- .Result -[source, result, role="noheader"] ----- -Rows: 3 - -+-------------+ -| innerReturn | -+-------------+ -| 'hello' | -| 'hello' | -| 'hello' | -+-------------+ ----- - +[role="queryresult",options="header,footer",cols="m"] +|=== +| +innerReturn+ +| +'hello'+ +| +'hello'+ +| +'hello'+ +d|Rows:3 +|=== ====== - Each execution of a `CALL` clause can observe changes from previous executions. @@ -93,7 +90,7 @@ Each execution of a `CALL` clause can observe changes from previous executions. ====== .Query -[source, cypher, role="noplay"] +[source, cypher] ---- UNWIND [0, 1, 2] AS x CALL { @@ -109,19 +106,19 @@ RETURN ---- .Result -[source, result, role="noheader"] ----- -Set Properties: 3 -Rows: 3 +[role="queryresult",options="header,footer",cols=""2*(b), + (a)-[:CHILD_OF]->(c) +---- +//// [[subquery-correlated-aggregation]] == Aggregation on imported variables @@ -379,7 +385,7 @@ Aggregations in subqueries are scoped to the subquery evaluation, also for impor The following example counts the number of younger persons for each person in the graph: .Query -[source, cypher, indent=0] +[source, cypher] ---- MATCH (p:Person) CALL { @@ -414,7 +420,7 @@ The following example uses a CSV file and the `LOAD CSV` clause to import more d It creates nodes in separate transactions using `+CALL { ... } IN TRANSACTIONS+`: .friends.csv -[source, csv, role="noheader"] +[source, csv] ---- 1,Bill,26 2,Max,27 @@ -424,7 +430,7 @@ It creates nodes in separate transactions using `+CALL { ... } IN TRANSACTIONS+` ---- .Query -[source, cypher, indent=0] +[source, cypher] ---- LOAD CSV FROM 'file:///friends.csv' AS line CALL { @@ -461,19 +467,8 @@ Using `+CALL { ... } IN TRANSACTIONS+` is the recommended way of deleting a larg .+DETACH DELETE+ ====== -//// -CREATE - (a:Person:Child {age: 20, name: 'Alice'}), - (b:Person {age: 27, name: 'Bob'}), - (c:Person:Parent {age: 65, name: 'Charlie'}), - (d:Person {age: 30, name: 'Dora'}), - (:Counter {count: 0}) - CREATE (a)-[:FRIEND_OF]->(b) - CREATE (a)-[:CHILD_OF]->(c) -//// - .Query -[source, cypher, indent=0] +[source, cypher] ---- MATCH (n) CALL { @@ -501,26 +496,15 @@ Modifying the subquery may result in `OutOfMemory` exceptions for sufficiently l ====== -.+DETACH DELTE+ +.+DETACH DELETE+ ====== The `+CALL { ... } IN TRANSACTIONS+` subquery should not be modified. Any necessary filtering can be done before the subquery. -//// -CREATE - (a:Person:Child {age: 20, name: 'Alice'}), - (b:Person {age: 27, name: 'Bob'}), - (c:Person:Parent {age: 65, name: 'Charlie'}), - (d:Person {age: 30, name: 'Dora'}), - (:Counter {count: 0}) - CREATE (a)-[:FRIEND_OF]->(b) - CREATE (a)-[:CHILD_OF]->(c) -//// - .Query -[source, cypher, indent=0] +[source, cypher] ---- MATCH (n:Label) WHERE n.prop > 100 CALL { @@ -558,7 +542,7 @@ The following is the same example but with one transaction every `2` input rows: ---- .Query -[source, cypher, indent=0] +[source, cypher] ---- LOAD CSV FROM 'file:///friends.csv' AS line CALL { @@ -591,7 +575,7 @@ You can also use `+CALL { ... } IN TRANSACTIONS OF n ROWS+` to delete all your d For example: .Query -[source, cypher, indent=0] +[source, cypher] ---- MATCH (n) CALL { @@ -632,7 +616,7 @@ In the following example, the last subquery execution in the second inner transa due to division by zero. .Query -[source, cypher, indent=0] +[source, cypher, role=test-fail] ---- UNWIND [4, 2, 1, 0] AS i CALL { @@ -642,8 +626,8 @@ CALL { RETURN i ---- -.Error -[source, error, role="noheader"] +.Error message +[source, error] ---- / by zero (Transactions committed: 1) ---- @@ -651,7 +635,7 @@ RETURN i When the failure occurred, the first transaction had already been committed, so the database contains two example nodes. .Query -[source, cypher, indent=0] +[source, cypher] ---- MATCH (e:Example) RETURN e.num @@ -685,7 +669,7 @@ Attempting any of the above, will throw an error. For example, the following query using a `WHERE` clause after an importing `WITH` clause will throw an error: .Query -[source, cypher, indent=0] +[source, cypher, role=test-fail] ---- UNWIND [[1,2],[1,2,3,4],[1,2,3,4,5]] AS l CALL { @@ -697,7 +681,7 @@ RETURN largeLists ---- .Error message -[source, output, role="noheader", indent=0] +[source, error] ---- Importing WITH should consist only of simple references to outside variables. WHERE is not allowed. @@ -708,7 +692,7 @@ This second `WITH` clause will act as a regular `WITH` clause. For example, the following query will not throw an error: .Query -[source, cypher, indent=0] +[source, cypher] ---- UNWIND [[1,2],[1,2,3,4],[1,2,3,4,5]] AS l CALL { @@ -720,3 +704,14 @@ CALL { RETURN largeLists ---- +.Result +[role="queryresult",options="header,footer",cols="1* Date: Mon, 30 Jan 2023 09:08:09 +0100 Subject: [PATCH 2/2] fix unterminated example block in alias page --- modules/ROOT/pages/aliases.adoc | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/ROOT/pages/aliases.adoc b/modules/ROOT/pages/aliases.adoc index 058fbd5a3..f9f708e9d 100644 --- a/modules/ROOT/pages/aliases.adoc +++ b/modules/ROOT/pages/aliases.adoc @@ -1331,8 +1331,6 @@ DROP ALIAS `northwind` IF EXISTS FOR DATABASE ====== -<<<<<<< HEAD -======= [role=enterprise-edition] [[alias-management-escaping]]