Skip to content

Commit 9fab0ab

Browse files
[Testing] Make a few more examples testable (#499)
I removed a few `test-skip` here and there, and removed some useless attributes from code blocks where I was editing already. Also added some comments on why some examples need to be skipped.
1 parent 7a62446 commit 9fab0ab

File tree

6 files changed

+62
-46
lines changed

6 files changed

+62
-46
lines changed

modules/ROOT/pages/administration/access-control/built-in-roles.adoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,7 @@ To restore the role to its original capabilities two steps are needed.
453453
First, execute `DROP ROLE admin`.
454454
Secondly, run these queries:
455455

456-
// we cannot test this right now cause we would delete the role the test user is logged with
457-
456+
// cannot test as it would require deleting the role the test user is logged with
458457
[source, cypher, role=noplay test-skip]
459458
----
460459
CREATE ROLE admin

modules/ROOT/pages/administration/access-control/manage-users.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ Users can change their password using `ALTER CURRENT USER SET PASSWORD`.
817817
The old password is required in addition to the new one, and either or both can be a string value or a string parameter.
818818
When a user executes this command it will change their password as well as set the `CHANGE NOT REQUIRED` flag.
819819

820+
// can't test, don't want to hardcode test user password
820821
[source, cypher, role=test-skip]
821822
----
822823
ALTER CURRENT USER

modules/ROOT/pages/clauses/merge.adoc

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
== Introduction
88

99
The `MERGE` clause either matches existing node patterns in the graph and binds them or, if not present, creates new data and binds that.
10-
In this way, it acts as a combination of `MATCH` and `CREATE` that allows for specific actions depending on whether the specified data was matched or created.
10+
In this way, it acts as a combination of `MATCH` and `CREATE` that allows for specific actions depending on whether the specified data was matched or created.
1111

1212
For example, `MERGE` can be used to specify that a graph must contain a node with a `Person` label and a specific `name` property.
1313
If there isn't a node with the specific `name` property, a new node will be created with that `name` property.
@@ -80,7 +80,7 @@ RETURN robert, labels(robert)
8080
A new node is created because there are no nodes labeled `Critic` in the database:
8181

8282
.Result
83-
[role="queryresult",options="header,footer",cols="2*<m"]
83+
[role="queryresult",options="header",cols="2*<m"]
8484
|===
8585
| +robert+ | +labels(robert)+
8686
| +{}+ | +["Critic"]+
@@ -90,7 +90,7 @@ A new node is created because there are no nodes labeled `Critic` in the databas
9090
[[merge-merge-single-node-with-properties]]
9191
=== Merge single node with properties
9292

93-
Merging a node with properties that differ from the properties on existing nodes in the graph will create a new node:
93+
Merging a node with properties that differ from the properties on existing nodes in the graph will create a new node:
9494

9595
.Query
9696
[source, cypher]
@@ -102,7 +102,7 @@ RETURN charlie
102102
A new node with the name `'Charlie Sheen'` is created since not all properties matched those set to the pre-existing `'Charlie Sheen'` node:
103103

104104
.Result
105-
[role="queryresult",options="header,footer",cols="1*<m"]
105+
[role="queryresult",options="header",cols="1*<m"]
106106
|===
107107
| +charlie+
108108
| +{"name":"Charlie Sheen","age":10}+
@@ -124,7 +124,7 @@ RETURN michael.name, michael.bornIn
124124
`'Michael Douglas'` is matched and the `name` and `bornIn` properties are returned:
125125

126126
.Result
127-
[role="queryresult",options="header,footer",cols="2*<m"]
127+
[role="queryresult",options="header",cols="2*<m"]
128128
|===
129129
| +michael.name+ | +michael.bornIn+
130130
| +"Michael Douglas"+ | +"New Jersey"+
@@ -149,7 +149,7 @@ As the `'New York'` node is not matched for the first bound node, it is created.
149149
However, the newly-created `'New York'` node is matched and bound for the second and third bound nodes.
150150

151151
.Result
152-
[role="queryresult",options="header,footer",cols="3*<m"]
152+
[role="queryresult",options="header",cols="3*<m"]
153153
|===
154154
| +person.name+ | +person.bornIn+ | +location+
155155
| +"Charlie Sheen"+ | +"New York"+ | +{name:"New York"}+
@@ -181,7 +181,7 @@ The query creates the `Person` node named `Keanu Reeves`, with a `bornIn` proper
181181
It also sets a timestamp for the `created` property.
182182

183183
.Result
184-
[role="queryresult",options="header,footer",cols="2*<m"]
184+
[role="queryresult",options="header",cols="2*<m"]
185185
|===
186186
| +keanu.name+ | +keanu.created+
187187
| +"Keanu Reeves"+ | +1655200898563+
@@ -205,7 +205,7 @@ RETURN person.name, person.found
205205
The query finds all the `Person` nodes, sets a property on them, and returns them:
206206

207207
.Result
208-
[role="queryresult",options="header,footer",cols="2*<m"]
208+
[role="queryresult",options="header",cols="2*<m"]
209209
|===
210210
| +person.name+ | +person.found+
211211
| +"Charlie Sheen"+ | +true+
@@ -235,7 +235,7 @@ Because the `Person` node named `Keanu Reeves` already exists, this query does n
235235
Instead, it adds a timestamp on the `lastSeen` property.
236236

237237
.Result
238-
[role="queryresult",options="header,footer",cols="3*<m"]
238+
[role="queryresult",options="header",cols="3*<m"]
239239
|===
240240
| +keanu.name+ | +keanu.created+ | +keanu.lastSeen+
241241
| +"Keanu Reeves"+ | +1655200902354+ | +1674655352124+
@@ -259,7 +259,7 @@ RETURN person.name, person.found, person.lastAccessed
259259
----
260260

261261
.Result
262-
[role="queryresult",options="header,footer",cols="3*<m"]
262+
[role="queryresult",options="header",cols="3*<m"]
263263
|===
264264
| +person.name+ | +person.found+ | +person.lastAccessed+
265265
| +"Charlie Sheen"+ | +true+ | +1655200903558+
@@ -293,7 +293,7 @@ RETURN charlie.name, type(r), wallStreet.title
293293
Note that in order to match or create a relationship when using `MERGE`, at least one bound node must be specified, which is done via the `MATCH` clause in the above example.
294294

295295
.Result
296-
[role="queryresult",options="header,footer",cols="3*<m"]
296+
[role="queryresult",options="header",cols="3*<m"]
297297
|===
298298
| +charlie.name+ | +type(r)+ | +wallStreet.title+
299299
| +"Charlie Sheen"+ | +"ACTED_IN"+ | +"Wall Street"+
@@ -318,7 +318,7 @@ When trying to `MERGE` a `Movie` node between them, Neo4j will not use any of th
318318
Instead, a new `Movie` node is created.
319319

320320
.Result
321-
[role="queryresult",options="header,footer",cols="1*<m"]
321+
[role="queryresult",options="header",cols="1*<m"]
322322
|===
323323
| +movie+
324324
| +{}+
@@ -345,7 +345,7 @@ As `'Charlie Sheen'` and `'Oliver Stone'` do not know each other in the example
345345
The direction of the created relationship is arbitrary.
346346

347347
.Result
348-
[role="queryresult",options="header,footer",cols="1*<m"]
348+
[role="queryresult",options="header",cols="1*<m"]
349349
|===
350350
| +r+
351351
| +{}+
@@ -371,7 +371,7 @@ The second `MERGE` creates a `BORN_IN` relationship between each person and a lo
371371
`'Charlie Sheen'`, `'Rob Reiner',` and `'Oliver Stone'` all have a `BORN_IN` relationship to the _same_ `Location` node (`'New York'`).
372372

373373
.Result
374-
[role="queryresult",options="header,footer",cols="3*<m"]
374+
[role="queryresult",options="header",cols="3*<m"]
375375
|===
376376
| +person.name+ | +person.bornIn+ | +location+
377377
| +"Charlie Sheen"+ | +"New York"+ | +{name:"New York"}+
@@ -402,7 +402,7 @@ As `'Charlie Sheen'` and `'Michael Douglas'` both have a chauffeur with the same
402402
This is in contrast to the example shown above in xref::clauses/merge.adoc#merge-merge-on-a-relationship-between-two-existing-nodes[Merge on a relationship between two existing nodes], where the first `MERGE` was used to bind the `Location` nodes and to prevent them from being recreated (and thus duplicated) on the second `MERGE`.
403403

404404
.Result
405-
[role="queryresult",options="header,footer",cols="3*<m"]
405+
[role="queryresult",options="header",cols="3*<m"]
406406
|===
407407
| +person.name+ | +person.chauffeurName+ | +chauffeur+
408408
| +"Charlie Sheen"+ | +"John Brown"+ | +{name:"John Brown"}+
@@ -446,7 +446,7 @@ RETURN laurence.name
446446
----
447447

448448
.Result
449-
[role="queryresult",options="header,footer",cols="1*<m"]
449+
[role="queryresult",options="header",cols="1*<m"]
450450
|===
451451
| +laurence.name+
452452
| +"Laurence Fishburne"+
@@ -466,7 +466,7 @@ RETURN oliver.name, oliver.bornIn
466466
----
467467

468468
.Result
469-
[role="queryresult",options="header,footer",cols="2*<m"]
469+
[role="queryresult",options="header",cols="2*<m"]
470470
|===
471471
| +oliver.name+ | +oliver.bornIn+
472472
| +"Oliver Stone"+ | +"New York"+
@@ -534,27 +534,28 @@ To use map parameters with `MERGE`, it is necessary to explicitly use the expect
534534
For more information on parameters, see xref::syntax/parameters.adoc[].
535535

536536
.Parameters
537-
[source,javascript, indent=0]
537+
[source, javascript]
538538
----
539539
{
540540
"param": {
541541
"name": "Keanu Reeves",
542-
"role": "Neo"
542+
"bornIn": "Beirut",
543+
"chauffeurName": "Eric Brown"
543544
}
544545
}
545546
----
546547

547548
.Query
548-
[source, cypher, role=test-skip]
549+
[source, cypher]
549550
----
550-
MERGE (person:Person {name: $param.name, role: $param.role})
551-
RETURN person.name, person.role
551+
MERGE (person:Person {name: $param.name, bornIn: $param.bornIn, chauffeurName: $param.chauffeurName})
552+
RETURN person.name, person.bornIn, person.chauffeurName
552553
----
553554

554555
.Result
555-
[role="queryresult",options="header,footer",cols="2*<m"]
556+
[role="queryresult",options="header",cols="3*<m"]
556557
|===
557-
| +person.name+ | +person.role+
558-
| +"Keanu Reeves"+ | +"Neo"+
558+
| person.name | person.bornIn | person.chauffeurName
559+
| "Keanu Reeves" | "Beirut" | "Eric Brown"
559560
|===
560561

modules/ROOT/pages/clauses/use.adoc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ When executing queries against a composite database, the `USE` clause must only
5555
[[query-use-examples]]
5656
== Examples
5757

58-
To create the database `myDatabase`, run the following query in a Neo4j database:
58+
////
5959
[source, cypher, role=test-setup]
6060
----
6161
CREATE DATABASE myDatabase;
62+
CREATE COMPOSITE DATABASE `myComposite`;
63+
CREATE ALIAS `myComposite`.`myConstituent` FOR DATABASE `myDatabase`;
6264
----
63-
65+
////
6466

6567
[[query-use-examples-query-graph]]
6668
=== Query a graph
@@ -80,7 +82,7 @@ MATCH (n) RETURN n
8082
In this example it is assumed that the DBMS contains a composite database named `myComposite`, which includes an alias named `myConstituent`:
8183

8284
.Query
83-
[source, cypher, role="test-skip"]
85+
[source, cypher]
8486
----
8587
USE myComposite.myConstituent
8688
MATCH (n) RETURN n
@@ -95,14 +97,15 @@ The built-in function `graph.byName()` can be used in the `USE` clause to resolv
9597
This example uses a composite database named `myComposite` that includes an alias named `myConstituent`:
9698

9799
.Query
98-
[source, cypher, role="test-skip"]
100+
[source, cypher]
99101
----
100102
USE graph.byName('myComposite.myConstituent')
101103
MATCH (n) RETURN n
102104
----
103105

104106
The argument can be any expression that evaluates to the name of a constituent graph - for example a parameter:
105-
// this can only run under composite databases
107+
108+
// can't run this through drivers, we need a value when initializing a session
106109
.Query
107110
[source, cypher, role=test-skip]
108111
----

modules/ROOT/pages/indexes-for-search-performance.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ The index is not immediately available, but is created in the background.
660660
.+CREATE LOOKUP INDEX+
661661
======
662662
663+
// Lookup indexes exist by default, recreating them would raise an error
663664
.Query
664665
[source, cypher, role=test-skip]
665666
----
@@ -703,6 +704,7 @@ The index is not immediately available, but is created in the background.
703704
.+CREATE LOOKUP INDEX+
704705
======
705706
707+
// Lookup indexes exist by default, recreating them would raise an error
706708
.Query
707709
[source, cypher, role=test-skip]
708710
----
@@ -746,6 +748,7 @@ Only one valid value exists for the index provider, `token-lookup-1.0`, which is
746748
.+CREATE LOOKUP INDEX+
747749
======
748750
751+
// Lookup indexes exist by default, recreating them would raise an error
749752
.Query
750753
[source, cypher, role=test-skip]
751754
----

modules/ROOT/pages/introduction/cypher_overview.adoc

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,30 @@
22
= Overview
33
:description: This section provides an overview of Cypher and its key differences compared to SQL.
44

5-
This section provides an overview of Cypher and a brief discussion of how Cypher differs to SQL.
5+
This section provides an overview of Cypher and a brief discussion of how Cypher differs to SQL.
6+
7+
////
8+
[source, cypher, role=test-setup]
9+
----
10+
MERGE (matrix:Movie {title: 'The Matrix', rating: 10})
11+
MERGE (keanu:Person {name: 'Keanu Reeves'})
12+
MERGE (keanu)-[:ACTED_IN]->(matrix)
13+
----
14+
////
615

716
== What is Cypher?
817

9-
Cypher is Neo4j’s declarative graph query language.
10-
It was created in 2011 by Neo4j engineers as an SQL-equivalent language for graph databases.
18+
Cypher is Neo4j’s declarative graph query language.
19+
It was created in 2011 by Neo4j engineers as an SQL-equivalent language for graph databases.
1120
Similar to SQL, Cypher lets users focus on _what_ to retrieve from graph, rather than _how_ to retrieve it.
1221
As such, Cypher enables users to realize the full potential of their property graph databases by allowing for efficient and expressive queries that reveal previously unknown data connections and clusters.
1322

14-
Cypher provides a visual way of matching patterns and relationships.
23+
Cypher provides a visual way of matching patterns and relationships.
1524
It relies on the following ascii-art type of syntax: `(nodes)-[:CONNECT_TO]->(otherNodes)`.
16-
Rounded brackets are used for circular nodes, and `-[:ARROWS]->` for relationships.
17-
Writing a query is effectively like drawing a pattern through the data in the graph.
25+
Rounded brackets are used for circular nodes, and `-[:ARROWS]->` for relationships.
26+
Writing a query is effectively like drawing a pattern through the data in the graph.
1827
In other words, entities such as nodes and their relationships are visually built into queries.
19-
This makes Cypher a highly intuitive language to both read and write.
28+
This makes Cypher a highly intuitive language to both read and write.
2029

2130
== Cypher and SQL: key differences
2231

@@ -27,8 +36,8 @@ However, there are some important differences between the two:
2736
*Cypher is schema-flexible*::
2837

2938
While it is both possible and advised to enforce partial schemas using xref:constraints/index.adoc[indexes and constraints], Cypher and Neo4j offers a greater degree of schema-flexibility than SQL and a relational database.
30-
More specifically, nodes and relationships in a Neo4j database do not have to have a specific property set to them because other nodes or relationships in the same graph have that property (unless there is an xref:constraints/examples.adoc#constraints-examples-node-property-existence[existence constraint created on that specific property]).
31-
This means that users are not required to use a fixed schema to represent data and that they can add new attributes and relationships as their graphs evolve.
39+
More specifically, nodes and relationships in a Neo4j database do not have to have a specific property set to them because other nodes or relationships in the same graph have that property (unless there is an xref:constraints/examples.adoc#constraints-examples-node-property-existence[existence constraint created on that specific property]).
40+
This means that users are not required to use a fixed schema to represent data and that they can add new attributes and relationships as their graphs evolve.
3241

3342
*Query order*::
3443

@@ -41,11 +50,11 @@ FROM movie
4150
WHERE movie.rating > 7
4251
----
4352
+
44-
[source, cypher, role=test-skip]
53+
[source, cypher]
4554
----
4655
MATCH (movie:Movie)
4756
WHERE movie.rating > 7
48-
RETURN movie.name
57+
RETURN movie.title
4958
----
5059

5160
*Cypher queries are more concise*::
@@ -62,15 +71,15 @@ FROM actors
6271
WHERE movies.title = "The Matrix"
6372
----
6473
+
65-
[source, cypher, role=test-skip]
74+
[source, cypher]
6675
----
6776
MATCH (actor:Actor)-[:ACTED_IN]->(movie:Movie {title: 'The Matrix'})
6877
RETURN actor.name
6978
----
7079

7180
== Cypher and APOC
7281

73-
Neo4j supports the APOC (Awesome Procedures on Cypher) Core library.
82+
Neo4j supports the APOC (Awesome Procedures on Cypher) Core library.
7483
The APOC Core library provides access to user-defined procedures and functions which extend the use of the Cypher query language into areas such as data integration, graph algorithms, and data conversion.
7584

76-
For more details, visit the link:{neo4j-docs-base-uri}/apoc/{page-version}[APOC Core page].
85+
For more details, visit the link:{neo4j-docs-base-uri}/apoc/{page-version}[APOC Core page].

0 commit comments

Comments
 (0)