buildEdgeGroupExpression.php
Table of Contents
Functions
- buildEdgeGroupExpression() : string
- Compiles the grouping dimension of a **relation**: the value a document is grouped by when that value lives on the document at the other end of an edge.
Functions
buildEdgeGroupExpression()
Compiles the grouping dimension of a **relation**: the value a document is grouped by when that value lives on the document at the other end of an edge.
buildEdgeGroupExpression(string $key, array<string|int, mixed> $definition, array<string|int, mixed>|string $path[, string $startVertex = AQL::DOC ][, ContainerInterface|null $container = null ]) : string
The expression is a sub-query written inline in the COLLECT, and it has
to be, because a grouped query never projects. The LET a projected relation
emits — the one a relational sort names — is produced by returnFields(),
which a grouped query does not call: doc is consumed by the COLLECT, so
there is nothing to project and no variable to reach for. The dimension
therefore carries its own traversal:
COLLECT author = FIRST( FOR author_v IN OUTBOUND doc articles_authors RETURN author_v.name )
AGGREGATE total = SUM( doc.amount )
FIRST() is what makes the dimension a scalar, and it is why only a
singular relation may be grouped on. The two alternatives were measured, and
neither is acceptable:
- keeping the sub-query as an array groups by the combination — three
buckets (
["Alice"],["Alice","Zoe"],["Zoe"]) for two authors; - unwinding the relation with a
FORbefore theCOLLECTduplicates the document once per related vertex, which inflates every other aggregate of the sameCOLLECT: over three documents worth 10, 20 and 30, aSUManswers 70 where the truth is 60, because the two-author document is counted twice.
The declaration is read through the same shared doors as the list — the
depth range, the row scope (AQL::WHERE / AQL::PRUNE) and the traversal
options — so a grouped dimension describes exactly the relation the list
projects. Read differently, it would put a label next to rows that contradict it.
Parameters
- $key : string
-
The dimension key; names the traversal variable (
<key>_v). - $definition : array<string|int, mixed>
-
The edge definition (
AQL::MODEL,AQL::DIRECTION, …). - $path : array<string|int, mixed>|string
-
The field of the related document carrying the value.
- $startVertex : string = AQL::DOC
-
The document the traversal departs from.
- $container : ContainerInterface|null = null
-
Resolves an
AQL::MODELgiven by container id.
Tags
Return values
string —The FIRST( FOR … RETURN … ) expression.