Skip to content

Commit

Permalink
escaped tags, added tags for LOAD CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
rsill-neo4j committed Dec 20, 2024
1 parent d932269 commit e49a21f
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 35 deletions.
8 changes: 4 additions & 4 deletions modules/ROOT/pages/clauses/finish.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ A query ending in `FINISH` -- instead of `RETURN` -- has no result but executes
The following read query successfully executes but has no results:

.Query
tag::clauses_finish_match[]
// tag::clauses_finish_match[]
[source, cypher]
----
MATCH (p:Person)
FINISH
----
end::clauses_finish_match[]
// end::clauses_finish_match[]

The following query has no result but creates one node with the label `Person`:

.Query
tag::clauses_finish_create[]
// tag::clauses_finish_create[]
[source, cypher]
----
CREATE (p:Person)
FINISH
----
end::clauses_finish_create[]
// end::clauses_finish_create[]

It is equivalent to the following query:

Expand Down
4 changes: 2 additions & 2 deletions modules/ROOT/pages/clauses/foreach.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ CREATE
This query will set the property `marked` to `true` on all nodes along a path.

.Query
tag::clauses_foreach[]
// tag::clauses_foreach[]
[source, cypher, indent=0]
----
MATCH p=(start)-[*]->(finish)
WHERE start.name = 'A' AND finish.name = 'D'
FOREACH (n IN nodes(p) | SET n.marked = true)
----
end::clauses_foreach[]
// end::clauses_foreach[]

.Result
[role="queryresult",options="footer",cols="1*<m"]
Expand Down
8 changes: 4 additions & 4 deletions modules/ROOT/pages/clauses/limit.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ Properties set: 1
`LIMIT` can be used as a standalone clause, or in conjunction with xref:clauses/order-by.adoc[`ORDER BY`] or xref:clauses/skip.adoc[`SKIP`]/xref:clauses/skip.adoc#offset-synonym[`OFFSET`].

.Standalone use of `LIMIT`
tag::clauses_limit_standalone[]
// tag::clauses_limit_standalone[]
[source, cypher]
----
MATCH (n)
LIMIT 2
RETURN collect(n.name) AS names
----
tag::clauses_limit_standalone[]
// end::clauses_limit_standalone[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand All @@ -187,7 +187,7 @@ The following query orders all nodes by `name` descending, skips the two first r
It then xref:functions/aggregating.adoc#functions-collect[collects] the results in a list.

.`LIMIT` used in conjunction with `ORDER BY` and `SKIP`
tag::clauses_limit[]
// tag::clauses_limit[]
[source, cypher]
----
MATCH (n)
Expand All @@ -196,7 +196,7 @@ SKIP 2
LIMIT 2
RETURN collect(n.name) AS names
----
end::clauses_limit[]
// end::clauses_limit[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down
16 changes: 15 additions & 1 deletion modules/ROOT/pages/clauses/load-csv.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ By default, paths are resolved relative to the Neo4j import directory.
----
.Query
// tag::clauses_load_csv_local_files[]
[source, cypher]
----
LOAD CSV FROM 'file:///artists.csv' AS row
MERGE (a:Artist {name: row[1], year: toInteger(row[2])})
RETURN a.name, a.year
----
// end::clauses_load_csv_local_files[]
.Result
[role="queryresult",options="header,footer",cols="2*<m"]
Expand Down Expand Up @@ -112,12 +114,14 @@ However, this means that insecure URLs on virtual hosts will not function unless
----
.Query
// tag::clauses_load_csv_remote_locations[]
[source, cypher]
----
LOAD CSV FROM 'https://data.neo4j.com/bands/artists.csv' AS row
MERGE (a:Artist {name: row[1], year: toInteger(row[2])})
RETURN a.name, a.year
----
// end::clauses_load_csv_remote_locations[]
.Result
[role="queryresult",options="header,footer",cols="2*<m"]
Expand Down Expand Up @@ -700,10 +704,11 @@ person_tmdbId,bio,born,bornIn,died,person_imdbId,name,person_poster,person_url
----
[NOTE]
The below query uses a xref:subqueries/call-subquery.adoc#variable-scope-clause[variable scope clause] (introduced in Neo4j 5.23) to import variables into the `CALL` subquery.
The query below uses a xref:subqueries/call-subquery.adoc#variable-scope-clause[variable scope clause] (introduced in Neo4j 5.23) to import variables into the `CALL` subquery.
If you are using an older version of Neo4j, use an xref:subqueries/call-subquery.adoc#importing-with[importing `WITH` clause] instead.
.Query
// tag::clauses_load_csv_transactions[]
[source, cypher]
----
LOAD CSV WITH HEADERS FROM 'https://data.neo4j.com/importing-cypher/persons.csv' AS row
Expand All @@ -712,6 +717,7 @@ CALL (row) {
SET p.name = row.name, p.born = row.born
} IN TRANSACTIONS OF 200 ROWS
----
// end::clauses_load_csv_transactions[]
.Result
[source, role="queryresult"]
Expand Down Expand Up @@ -746,11 +752,13 @@ A common use case for this function is to generate sequential unique IDs for CSV
----
.Query
// tag::clauses_load_csv_linenumber[]
[source, cypher]
----
LOAD CSV FROM 'file:///artists.csv' AS row
RETURN linenumber() AS number, row
----
// end::clauses_load_csv_linenumber[]
.Result
[role="queryresult",options="header,footer",cols="2*<m"]
Expand Down Expand Up @@ -781,11 +789,13 @@ The xref:functions/load-csv.adoc#functions-file[`file()`] function provides the
----
.Query
// tag::clauses_load_csv_file[]
[source, cypher, role=test-result-skip]
----
LOAD CSV FROM 'file:///artists.csv' AS row
RETURN DISTINCT file() AS path
----
// end::clauses_load_csv_file[]
.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down Expand Up @@ -832,6 +842,7 @@ Id,Name,Year
----
.Query
// tag::clauses_load_csv_headers[]
[source, cypher]
----
LOAD CSV WITH HEADERS FROM 'file:///artists-with-headers.csv' AS row
Expand All @@ -840,6 +851,7 @@ RETURN
a.name AS name,
a.year AS year
----
// end::clauses_load_csv_headers[]
.Result
[role="queryresult",options="header,footer",cols="2*<m"]
Expand Down Expand Up @@ -875,11 +887,13 @@ If you try to import a file that doesn't use `,` as field delimiter and you also
----
.Query
// tag::clauses_load_csv_field_terminator[]
[source, cypher]
----
LOAD CSV FROM 'file:///artists-fieldterminator.csv' AS row FIELDTERMINATOR ';'
MERGE (:Artist {name: row[1], year: toInteger(row[2])})
----
// end::clauses_load_csv_field_terminator[]
.Result
[source, role="queryresult"]
Expand Down
16 changes: 8 additions & 8 deletions modules/ROOT/pages/clauses/order-by.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ CREATE
`ORDER BY` is used to sort the output.

.Query
tag::clauses_order_by[]
// tag::clauses_order_by[]
[source, cypher]
----
MATCH (n)
RETURN n.name, n.age
ORDER BY n.name
----
end::clauses_order_by[]
// end::clauses_order_by[]

The nodes are returned, sorted by their name.

Expand All @@ -69,14 +69,14 @@ You can order by multiple properties by stating each variable in the `ORDER BY`
Cypher will sort the result by the first variable listed, and for equals values, go to the next property in the `ORDER BY` clause, and so on.

.Query
tag::clauses_order_by_multiple[]
// tag::clauses_order_by_multiple[]
[source, cypher]
----
MATCH (n)
RETURN n.name, n.age
ORDER BY n.age, n.name
----
end::clauses_order_by_multiple[]
// end::clauses_order_by_multiple[]

This returns the nodes, sorted first by their age, and then by their name.

Expand Down Expand Up @@ -250,14 +250,14 @@ Read more about this capability in xref::indexes/search-performance-indexes/usin


.Standalone use of `ORDER BY`
tag::clauses_order_by_standalone[]
// tag::clauses_order_by_standalone[]
[source, cypher]
----
MATCH (n)
ORDER BY n.name
RETURN collect(n.name) AS names
----
end::clauses_order_by_standalone[]
// end::clauses_order_by_standalone[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand All @@ -270,7 +270,7 @@ end::clauses_order_by_standalone[]
The following query orders all nodes by `name` descending, skips the first row and limits the results to one row.

.`ORDER BY` used in conjunction with `SKIP` and `LIMIT`
tag::clauses_order_by_descending[]
// tag::clauses_order_by_descending[]
[source, cypher]
----
MATCH (n)
Expand All @@ -279,7 +279,7 @@ SKIP 1
LIMIT 1
RETURN n.name AS name
----
end::clauses_order_by_descending[]
// end::clauses_order_by_descending[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down
12 changes: 6 additions & 6 deletions modules/ROOT/pages/clauses/skip.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ d|Rows: 2
The following query returns the middle two rows, with `SKIP` skipping the first and xref:clauses/limit.adoc[`LIMIT`] removing the final two.
.Query
// tag::clauses_skip[]
[source, cypher]
tag::clauses_skip[]
----
MATCH (n)
RETURN n.name
ORDER BY n.name
SKIP 1
LIMIT 2
----
end::clauses_skip[]
// end::clauses_skip[]
.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down Expand Up @@ -128,14 +128,14 @@ d|Rows: 4
`SKIP` can be used as a standalone clause, or in conjunction with xref:clauses/order-by.adoc[`ORDER BY`] or xref:clauses/limit.adoc[`LIMIT`].

.Standalone use of `SKIP`
tag::clauses_skip_standalone[]
// tag::clauses_skip_standalone[]
[source, cypher]
----
MATCH (n)
SKIP 2
RETURN collect(n.name) AS names
----
end::clauses_skip_standalone[]
// end::clauses_skip_standalone[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down Expand Up @@ -173,7 +173,7 @@ RETURN collect(n.name) AS names
`OFFSET` was introduced as part of Cypher's xref:appendix/gql-conformance/index.adoc[] and can be used as a synonym to `SKIP`.

.Query
tag::clauses_skip_offset[]
// tag::clauses_skip_offset[]
[source, cypher]
----
MATCH (n)
Expand All @@ -182,7 +182,7 @@ OFFSET 2
LIMIT 2
RETURN collect(n.name) AS names
----
end::clauses_skip_offset[]
// end::clauses_skip_offset[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down
12 changes: 6 additions & 6 deletions modules/ROOT/pages/clauses/unwind.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ The `UNWIND` clause requires you to specify a new name for the inner values.
We want to transform the literal list into rows named `x` and return them.

.Query
tag::clauses_unwind_list[]
// tag::clauses_unwind_list[]
[source, cypher]
----
UNWIND [1, 2, 3, null] AS x
RETURN x, 'val' AS y
----
end::clauses_unwind_list[]
// end::clauses_unwind_list[]

Each value of the original list -- including `null` -- is returned as an individual row.

Expand Down Expand Up @@ -111,15 +111,15 @@ The two lists -- _a_ and _b_ -- are concatenated to form a new list, which is th
Multiple `UNWIND` clauses can be chained to unwind nested list elements.

.Query
tag::clauses_unwind_nested_list[]
// tag::clauses_unwind_nested_list[]
[source, cypher]
----
WITH [[1, 2], [3, 4], 5] AS nested
UNWIND nested AS x
UNWIND x AS y
RETURN y
----
end::clauses_unwind_nested_list[]
// end::clauses_unwind_nested_list[]

The first `UNWIND` results in three rows for `x`, each of which contains an element of the original list (two of which are also lists); namely, `[1, 2]`, `[3, 4]`, and `5`.
The second `UNWIND` then operates on each of these rows in turn, resulting in five rows for `y`.
Expand Down Expand Up @@ -216,15 +216,15 @@ Create a number of nodes and relationships from a parameter-list without using `
----

.Query
tag::clauses_unwind_create_nodes[]
// tag::clauses_unwind_create_nodes[]
[source, cypher]
----
UNWIND $events AS event
MERGE (y:Year {year: event.year})
MERGE (y)<-[:IN]-(e:Event {id: event.id})
RETURN e.id AS x ORDER BY x
----
end::clauses_unwind_create_nodes[]
// end::clauses_unwind_create_nodes[]

Each value of the original list is unwound and passed through `MERGE` to find or create the nodes and relationships.

Expand Down
8 changes: 4 additions & 4 deletions modules/ROOT/pages/clauses/use.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,27 @@ CREATE ALIAS `myComposite`.`myConstituent` FOR DATABASE `myDatabase`;
This example assumes that the DBMS contains a database named `myDatabase`:

.Query
tag::clauses_use[]
// tag::clauses_use[]
[source, cypher]
----
USE myDatabase
MATCH (n) RETURN n
----
end::clauses_use[]
// end::clauses_use[]

[[query-use-examples-query-composite-database-constituent-graph]]
=== Query a composite database constituent graph

In this example it is assumed that the DBMS contains a composite database named `myComposite`, which includes an alias named `myConstituent`:

.Query
tag::clauses_use_composite[]
// tag::clauses_use_composite[]
[source, cypher]
----
USE myComposite.myConstituent
MATCH (n) RETURN n
----
end::clauses_use_composite[]
// end::clauses_use_composite[]


[[query-use-examples-query-composite-database-constituent-graph-dynamically]]
Expand Down

0 comments on commit e49a21f

Please sign in to comment.