Skip to content

Commit 311dee3

Browse files
authored
DOC-816 | Deduced vertex collections from named graphs (#799)
* Release notes * Fix typo * Remove mention of vertexCollections and add section about graph queries in cluster for path searches * Modify release notes example * Fix/unify examples
1 parent c2609c7 commit 311dee3

File tree

12 files changed

+589
-9
lines changed

12 files changed

+589
-9
lines changed

site/content/3.12/aql/graphs/all-shortest-paths.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,56 @@ All collections in the list that do not specify their own direction use the
117117
direction defined after `IN` (here: `OUTBOUND`). This allows using a different
118118
direction for each collection in your path search.
119119

120+
### Graph path searches in a cluster
121+
122+
Due to the nature of graphs, edges may reference nodes from arbitrary
123+
collections. Following the paths can thus involve documents from various
124+
collections and it is not possible to predict which are visited in a
125+
traversal. Which collections need to be loaded by the graph engine can only be
126+
determined at run time.
127+
128+
Use the [`WITH` operation](../high-level-operations/with.md) to specify the
129+
node collections you expect to be involved. This is required for traversals
130+
using collection sets in cluster deployments. Declare the collection of the
131+
start node as well if it's not declared already (like by a `FOR` loop).
132+
133+
{{< tip >}}
134+
From v3.12.6 onward, node collections are automatically deduced for graph
135+
queries using collection sets / anonymous graphs if there is a named graph with
136+
a matching edge collection in its edge definitions.
137+
138+
For example, suppose you have two node collections, `person` and `movie`, and
139+
an `acts_in` edge collection that connects them. If you want to run a path search
140+
query that starts (and ends) at a person that you specify with its document ID,
141+
you need to declare both node collections at the beginning of the query:
142+
143+
```aql
144+
WITH person, movie
145+
FOR p IN ANY ALL_SHORTEST_PATHS "person/1544" TO "person/52560" acts_in
146+
RETURN p.vertices[*].label
147+
```
148+
149+
However, if there is a named graph that includes an edge definition for the
150+
`acts_in` edge collection, with `person` as the _from_ collection and `movie`
151+
as the _to_ collection, you can omit `WITH person, movie`. That is, if you
152+
specify `acts_in` as an edge collection in an anonymous graph query, all
153+
named graphs are checked for this edge collection, and if there is a matching
154+
edge definition, its node collections are automatically added as data sources to
155+
the query.
156+
157+
```aql
158+
FOR p IN ANY ALL_SHORTEST_PATHS "person/1544" TO "person/52560" acts_in
159+
RETURN p.vertices[*].label
160+
161+
// Chris Rock --> Dogma <-- Ben Affleck --> Surviving Christmas <-- Jennifer Morrison
162+
// Chris Rock --> The Longest Yard <-- Rob Schneider --> Big Stan <-- Jennifer Morrison
163+
// Chris Rock --> Down to Earth <-- John Cho --> Star Trek <-- Jennifer Morrison
164+
```
165+
166+
You can still declare collections manually, in which case they are added as
167+
data sources in addition to automatically deduced collections.
168+
{{< /tip >}}
169+
120170
## Examples
121171

122172
Load an example graph to get a named graph that reflects some possible

site/content/3.12/aql/graphs/k-paths.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,57 @@ All collections in the list that do not specify their own direction use the
188188
direction defined after `IN` (here: `OUTBOUND`). This allows to use a different
189189
direction for each collection in your path search.
190190

191+
### Graph path searches in a cluster
192+
193+
Due to the nature of graphs, edges may reference nodes from arbitrary
194+
collections. Following the paths can thus involve documents from various
195+
collections and it is not possible to predict which are visited in a
196+
traversal. Which collections need to be loaded by the graph engine can only be
197+
determined at run time.
198+
199+
Use the [`WITH` operation](../high-level-operations/with.md) to specify the
200+
node collections you expect to be involved. This is required for traversals
201+
using collection sets in cluster deployments. Declare the collection of the
202+
start node as well if it's not declared already (like by a `FOR` loop).
203+
204+
{{< tip >}}
205+
From v3.12.6 onward, node collections are automatically deduced for graph
206+
queries using collection sets / anonymous graphs if there is a named graph with
207+
a matching edge collection in its edge definitions.
208+
209+
For example, suppose you have two node collections, `person` and `movie`, and
210+
an `acts_in` edge collection that connects them. If you want to run a path search
211+
query that starts (and ends) at a person that you specify with its document ID,
212+
you need to declare both node collections at the beginning of the query:
213+
214+
```aql
215+
WITH person, movie
216+
FOR p IN 4 ANY K_PATHS "person/1544" TO "person/52560" acts_in
217+
LIMIT 2
218+
RETURN p.vertices[*].label
219+
```
220+
221+
However, if there is a named graph that includes an edge definition for the
222+
`acts_in` edge collection, with `person` as the _from_ collection and `movie`
223+
as the _to_ collection, you can omit `WITH person, movie`. That is, if you
224+
specify `acts_in` as an edge collection in an anonymous graph query, all
225+
named graphs are checked for this edge collection, and if there is a matching
226+
edge definition, its node collections are automatically added as data sources to
227+
the query.
228+
229+
```aql
230+
FOR p IN 4 ANY K_PATHS "person/1544" TO "person/52560" acts_in
231+
LIMIT 2
232+
RETURN p.vertices[*].label
233+
234+
// Chris Rock --> Dogma <-- Ben Affleck --> Surviving Christmas <-- Jennifer Morrison
235+
// Chris Rock --> The Longest Yard <-- Rob Schneider --> Big Stan <-- Jennifer Morrison
236+
```
237+
238+
You can still declare collections manually, in which case they are added as
239+
data sources in addition to automatically deduced collections.
240+
{{< /tip >}}
241+
191242
## Examples
192243

193244
You can load the `kShortestPathsGraph` example graph to get a named graph that

site/content/3.12/aql/graphs/k-shortest-paths.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,57 @@ All collections in the list that do not specify their own direction use the
186186
direction defined after `IN` (here: `OUTBOUND`). This allows to use a different
187187
direction for each collection in your path search.
188188

189+
### Graph path searches in a cluster
190+
191+
Due to the nature of graphs, edges may reference nodes from arbitrary
192+
collections. Following the paths can thus involve documents from various
193+
collections and it is not possible to predict which are visited in a
194+
traversal. Which collections need to be loaded by the graph engine can only be
195+
determined at run time.
196+
197+
Use the [`WITH` operation](../high-level-operations/with.md) to specify the
198+
node collections you expect to be involved. This is required for traversals
199+
using collection sets in cluster deployments. Declare the collection of the
200+
start node as well if it's not declared already (like by a `FOR` loop).
201+
202+
{{< tip >}}
203+
From v3.12.6 onward, node collections are automatically deduced for graph
204+
queries using collection sets / anonymous graphs if there is a named graph with
205+
a matching edge collection in its edge definitions.
206+
207+
For example, suppose you have two node collections, `person` and `movie`, and
208+
an `acts_in` edge collection that connects them. If you want to run a path search
209+
query that starts (and ends) at a person that you specify with its document ID,
210+
you need to declare both node collections at the beginning of the query:
211+
212+
```aql
213+
WITH person, movie
214+
FOR p IN ANY K_SHORTEST_PATHS "person/1544" TO "person/52560" acts_in
215+
LIMIT 2
216+
RETURN p.vertices[*].label
217+
```
218+
219+
However, if there is a named graph that includes an edge definition for the
220+
`acts_in` edge collection, with `person` as the _from_ collection and `movie`
221+
as the _to_ collection, you can omit `WITH person, movie`. That is, if you
222+
specify `acts_in` as an edge collection in an anonymous graph query, all
223+
named graphs are checked for this edge collection, and if there is a matching
224+
edge definition, its node collections are automatically added as data sources to
225+
the query.
226+
227+
```aql
228+
FOR p IN ANY K_SHORTEST_PATHS "person/1544" TO "person/52560" acts_in
229+
LIMIT 2
230+
RETURN p.vertices[*].label
231+
232+
// Chris Rock --> Dogma <-- Ben Affleck --> Surviving Christmas <-- Jennifer Morrison
233+
// Chris Rock --> The Longest Yard <-- Rob Schneider --> Big Stan <-- Jennifer Morrison
234+
```
235+
236+
You can still declare collections manually, in which case they are added as
237+
data sources in addition to automatically deduced collections.
238+
{{< /tip >}}
239+
189240
## Examples
190241

191242
You can load the `kShortestPathsGraph` example graph to get a named graph that

site/content/3.12/aql/graphs/shortest-path.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,54 @@ All collections in the list that do not specify their own direction use the
145145
direction defined after `IN` (here: `OUTBOUND`). This allows you to use a different
146146
direction for each collection in your path search.
147147

148+
### Graph path searches in a cluster
149+
150+
Due to the nature of graphs, edges may reference nodes from arbitrary
151+
collections. Following the paths can thus involve documents from various
152+
collections and it is not possible to predict which are visited in a
153+
traversal. Which collections need to be loaded by the graph engine can only be
154+
determined at run time.
155+
156+
Use the [`WITH` operation](../high-level-operations/with.md) to specify the
157+
node collections you expect to be involved. This is required for traversals
158+
using collection sets in cluster deployments. Declare the collection of the
159+
start node as well if it's not declared already (like by a `FOR` loop).
160+
161+
{{< tip >}}
162+
From v3.12.6 onward, node collections are automatically deduced for graph
163+
queries using collection sets / anonymous graphs if there is a named graph with
164+
a matching edge collection in its edge definitions.
165+
166+
For example, suppose you have two node collections, `person` and `movie`, and
167+
an `acts_in` edge collection that connects them. If you want to run a path search
168+
query that starts (and ends) at a person that you specify with its document ID,
169+
you need to declare both node collections at the beginning of the query:
170+
171+
```aql
172+
WITH person, movie
173+
FOR v IN ANY SHORTEST_PATH "person/1544" TO "person/52560" acts_in
174+
RETURN v.label
175+
```
176+
177+
However, if there is a named graph that includes an edge definition for the
178+
`acts_in` edge collection, with `person` as the _from_ collection and `movie`
179+
as the _to_ collection, you can omit `WITH person, movie`. That is, if you
180+
specify `acts_in` as an edge collection in an anonymous graph query, all
181+
named graphs are checked for this edge collection, and if there is a matching
182+
edge definition, its node collections are automatically added as data sources to
183+
the query.
184+
185+
```aql
186+
FOR v IN ANY SHORTEST_PATH "person/1544" TO "person/52560" acts_in
187+
RETURN v.label
188+
189+
// Chris Rock --> Dogma <-- Ben Affleck --> Surviving Christmas <-- Jennifer Morrison
190+
```
191+
192+
You can still declare collections manually, in which case they are added as
193+
data sources in addition to automatically deduced collections.
194+
{{< /tip >}}
195+
148196
## Conditional shortest path
149197

150198
The `SHORTEST_PATH` computation only finds an unconditioned shortest path.

site/content/3.12/aql/graphs/traversals.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,50 @@ collections and it is not possible to predict which are visited in a
342342
traversal. Which collections need to be loaded by the graph engine can only be
343343
determined at run time.
344344

345-
Use the [`WITH` statement](../high-level-operations/with.md) to specify the collections you
346-
expect to be involved. This is required for traversals using collection sets
347-
in cluster deployments.
345+
Use the [`WITH` operation](../high-level-operations/with.md) to specify the
346+
node collections you expect to be involved. This is required for traversals
347+
using collection sets in cluster deployments. Declare the collection of the
348+
start node as well if it's not declared already (like by a `FOR` loop).
349+
350+
{{< tip >}}
351+
From v3.12.6 onward, node collections are automatically deduced for graph
352+
queries using collection sets / anonymous graphs if there is a named graph with
353+
a matching edge collection in its edge definitions.
354+
355+
For example, suppose you have two node collections, `person` and `movie`, and
356+
an `acts_in` edge collection that connects them. If you want to run a traversal
357+
query that starts at a person that you specify with its document ID,
358+
you need to declare both node collections at the beginning of the query:
359+
360+
```aql
361+
WITH person, movie
362+
FOR v, IN 0..1 OUTBOUND "person/1544" acts_in
363+
LIMIT 4
364+
RETURN v.label
365+
```
366+
367+
However, if there is a named graph that includes an edge definition for the
368+
`acts_in` edge collection, with `person` as the _from_ collection and `movie`
369+
as the _to_ collection, you can omit `WITH person, movie`. That is, if you
370+
specify `acts_in` as an edge collection in an anonymous graph query, all
371+
named graphs are checked for this edge collection, and if there is a matching
372+
edge definition, its node collections are automatically added as data sources to
373+
the query.
374+
375+
```aql
376+
FOR v, IN 0..1 OUTBOUND "person/1544" acts_in
377+
LIMIT 4
378+
RETURN v.label
379+
380+
// Chris Rock
381+
// A.I. Artificial Intelligence
382+
// Lethal Weapon 4
383+
// Madagascar
384+
```
385+
386+
You can still declare collections manually, in which case they are added as
387+
data sources in addition to automatically deduced collections.
388+
{{< /tip >}}
348389

349390
## Pruning
350391

site/content/3.12/release-notes/version-3.12/whats-new-in-3-12.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,50 @@ Indexes used:
13111311
10 idx_1836452431376941056 persistent coll
13121312
```
13131313

1314+
### Deduction of node collection for graph queries
1315+
1316+
<small>Introduced in: v3.12.6</small>
1317+
1318+
AQL graph traversals and path searches using anonymous graphs / collection sets
1319+
require that you declare all involved node collections upfront for cluster
1320+
deployments. That is, you need to use the `WITH` operation to list the collections
1321+
edges may point to, as well as the collection of the start node if not declared
1322+
otherwise. This also applies to single servers if the `--query.require-with`
1323+
startup option is enabled for parity between both deployment modes.
1324+
1325+
For example, assume you have two node collections, `person` and `movie`, and
1326+
edges pointing from one to the other stored in an `acts_in` edge collection.
1327+
If you want to run a traversal query starting from a person that you specify
1328+
with its document ID, you need to declare both node collections at the
1329+
beginning of the query:
1330+
1331+
```aql
1332+
WITH person, movie
1333+
FOR v IN 0..1 OUTBOUND "person/1544" acts_in
1334+
LIMIT 4
1335+
RETURN v.label
1336+
```
1337+
1338+
From v3.12.6 onward, the node collections can be automatically inferred if there
1339+
is a named graph using the same edge collection(s).
1340+
1341+
For example, assume there is a named graph that includes an edge definition for
1342+
the `acts_in` edge collection, with `person` as the _from_ collection and `movie`
1343+
as the _to_ collection. If you now specify `acts_in` as an edge collection in
1344+
an anonymous graph query, all named graphs are checked for this edge collection,
1345+
and if there is a matching edge definition, its node collections are automatically
1346+
added as data sources to the query. You no longer have to manually declare the
1347+
`person` and `movie` collections:
1348+
1349+
```aql
1350+
FOR v IN 0..1 OUTBOUND "person/1544" acts_in
1351+
LIMIT 4
1352+
RETURN v.label
1353+
```
1354+
1355+
You can still declare collections manually, in which case they are added as
1356+
data sources in addition to automatically deduced collections.
1357+
13141358
### Optional elevation for GeoJSON Points
13151359

13161360
<small>Introduced in: v3.11.14-2, v3.12.6</small>

site/content/3.13/aql/graphs/all-shortest-paths.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,58 @@ All collections in the list that do not specify their own direction use the
117117
direction defined after `IN` (here: `OUTBOUND`). This allows using a different
118118
direction for each collection in your path search.
119119

120+
### Graph path searches in a cluster
121+
122+
Due to the nature of graphs, edges may reference nodes from arbitrary
123+
collections. Following the paths can thus involve documents from various
124+
collections and it is not possible to predict which are visited in a path
125+
search - unless you use named graphs that define all node and edge collections
126+
that belong to them and the graph data is consistent.
127+
128+
If you use anonymous graphs / collection sets for graph queries, which node
129+
collections need to be loaded by the graph engine can deduced automatically if
130+
there is a named graph with a matching edge collection in its edge definitions
131+
(introduced in v3.12.6). Edge collections are always declared explicitly in
132+
queries, directly or via referencing a named graph.
133+
134+
Without a named graph, the involved node collections can only be determined at
135+
run time. Use the [`WITH` operation](../high-level-operations/with.md) to
136+
declare the node collections upfront. This is required for path searches
137+
using collection sets in cluster deployments (if there is no named graph to
138+
deduce the node collections from). Declare the collection of the start node as
139+
well if it's not declared already (like by a `FOR` loop).
140+
141+
For example, suppose you have two node collections, `person` and `movie`, and
142+
an `acts_in` edge collection that connects them. If you want to run a path search
143+
query that starts (and ends) at a person that you specify with its document ID,
144+
you need to declare both node collections at the beginning of the query:
145+
146+
```aql
147+
WITH person, movie
148+
FOR p IN ANY ALL_SHORTEST_PATHS "person/1544" TO "person/52560" acts_in
149+
RETURN p.vertices[*].label
150+
```
151+
152+
However, if there is a named graph that includes an edge definition for the
153+
`acts_in` edge collection, with `person` as the _from_ collection and `movie`
154+
as the _to_ collection, you can omit `WITH person, movie`. That is, if you
155+
specify `acts_in` as an edge collection in an anonymous graph query, all
156+
named graphs are checked for this edge collection, and if there is a matching
157+
edge definition, its node collections are automatically added as data sources to
158+
the query.
159+
160+
```aql
161+
FOR p IN ANY ALL_SHORTEST_PATHS "person/1544" TO "person/52560" acts_in
162+
RETURN p.vertices[*].label
163+
164+
// Chris Rock --> Dogma <-- Ben Affleck --> Surviving Christmas <-- Jennifer Morrison
165+
// Chris Rock --> The Longest Yard <-- Rob Schneider --> Big Stan <-- Jennifer Morrison
166+
// Chris Rock --> Down to Earth <-- John Cho --> Star Trek <-- Jennifer Morrison
167+
```
168+
169+
You can still declare collections manually, in which case they are added as
170+
data sources in addition to automatically deduced collections.
171+
120172
## Examples
121173

122174
Load an example graph to get a named graph that reflects some possible

0 commit comments

Comments
 (0)