Skip to content

Commit 6c52aca

Browse files
authored
Conditional execution procedures (#203)
1 parent 8c2d8e9 commit 6c52aca

File tree

47 files changed

+533
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+533
-14
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
MATCH (n) DETACH DELETE n;
2+
MERGE (a: Node {id: 0}) MERGE (b: Node {id: 1}) CREATE (a)-[:RELATION]->(b);
3+
MERGE (a: Node {id: 0}) MERGE (b: Node {id: 2}) CREATE (a)-[:RELATION]->(b);
4+
MERGE (a: Node {id: 1}) MERGE (b: Node {id: 2}) CREATE (a)-[:RELATION]->(b);
5+
MERGE (a: Node {id: 2}) MERGE (b: Node {id: 3}) CREATE (a)-[:RELATION]->(b);
6+
MERGE (a: Node {id: 3}) MERGE (b: Node {id: 4}) CREATE (a)-[:RELATION]->(b);
7+
MERGE (a: Node {id: 3}) MERGE (b: Node {id: 5}) CREATE (a)-[:RELATION]->(b);
8+
MERGE (a: Node {id: 4}) MERGE (b: Node {id: 5}) CREATE (a)-[:RELATION]->(b);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
query: >
2+
MATCH (n:Node)
3+
WITH size(collect(n)) as n_nodes
4+
CALL do.case([n_nodes = 0, "RETURN 'empty' AS graph_status;",
5+
n_nodes > 0, "RETURN 'not empty' as graph_status;"],
6+
"RETURN 'unexpected' as graph_status")
7+
YIELD value
8+
RETURN value.graph_status AS graph_status;
9+
output:
10+
- graph_status: "not empty"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
MATCH (n) DETACH DELETE n;
2+
MERGE (a: Node {id: 0}) MERGE (b: Node {id: 1}) CREATE (a)-[:RELATION]->(b);
3+
MERGE (a: Node {id: 0}) MERGE (b: Node {id: 2}) CREATE (a)-[:RELATION]->(b);
4+
MERGE (a: Node {id: 1}) MERGE (b: Node {id: 2}) CREATE (a)-[:RELATION]->(b);
5+
MERGE (a: Node {id: 2}) MERGE (b: Node {id: 3}) CREATE (a)-[:RELATION]->(b);
6+
MERGE (a: Node {id: 3}) MERGE (b: Node {id: 4}) CREATE (a)-[:RELATION]->(b);
7+
MERGE (a: Node {id: 3}) MERGE (b: Node {id: 5}) CREATE (a)-[:RELATION]->(b);
8+
MERGE (a: Node {id: 4}) MERGE (b: Node {id: 5}) CREATE (a)-[:RELATION]->(b);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
query: >
2+
MATCH (n:Node)
3+
WITH size(collect(n)) as n_nodes
4+
CALL do.when(n_nodes = 0,
5+
"RETURN 'empty' AS graph_status;",
6+
"RETURN 'not empty' as graph_status;")
7+
YIELD value
8+
RETURN value.graph_status AS graph_status;
9+
output:
10+
- graph_status: "not empty"

e2e/do_test/disallowed_query_group/test_do_case/input.cyp

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
query: >
2+
CALL do.case([TRUE, "CREATE INDEX ON :Node(id);"],
3+
"")
4+
YIELD value;
5+
6+
exception: >
7+
The query "CREATE INDEX ON :Node(id);" isn’t supported by `do.case` because it would execute a global operation.

e2e/do_test/disallowed_query_group/test_do_when/input.cyp

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
query: >
2+
CALL do.when(TRUE,
3+
"CREATE INDEX ON :Node(id);",
4+
"")
5+
YIELD value;
6+
7+
exception: >
8+
The query "CREATE INDEX ON :Node(id);" isn’t supported by `do.when` because it would execute a global operation.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
MATCH (n) DETACH DELETE n;
2+
MERGE (a: Node {id: 0}) MERGE (b: Node {id: 1}) CREATE (a)-[:RELATION]->(b);
3+
MERGE (a: Node {id: 0}) MERGE (b: Node {id: 2}) CREATE (a)-[:RELATION]->(b);
4+
MERGE (a: Node {id: 1}) MERGE (b: Node {id: 2}) CREATE (a)-[:RELATION]->(b);
5+
MERGE (a: Node {id: 2}) MERGE (b: Node {id: 3}) CREATE (a)-[:RELATION]->(b);
6+
MERGE (a: Node {id: 3}) MERGE (b: Node {id: 4}) CREATE (a)-[:RELATION]->(b);
7+
MERGE (a: Node {id: 3}) MERGE (b: Node {id: 5}) CREATE (a)-[:RELATION]->(b);
8+
MERGE (a: Node {id: 4}) MERGE (b: Node {id: 5}) CREATE (a)-[:RELATION]->(b);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
query: >
2+
CALL do.case([FALSE, "MATCH (n) RETURN n;",
3+
FALSE, "MATCH (n) WHERE n.id < 4 RETURN n;"],
4+
"MATCH (n) WHERE n.id < 2 RETURN n;")
5+
YIELD value
6+
WITH collect(value.n) as nodes
7+
RETURN SIZE(nodes) AS n_nodes;
8+
9+
output:
10+
- n_nodes: 2

0 commit comments

Comments
 (0)