expandArrayPath.php
Table of Contents
Functions
- expandArrayPath() : array{0: string[], 1: string}
- Unwinds an array-expansion path into the chain of `FOR` hops AQL needs to walk it, plus the reference of the projected leaf.
Functions
expandArrayPath()
Unwinds an array-expansion path into the chain of `FOR` hops AQL needs to walk it, plus the reference of the projected leaf.
expandArrayPath(string $property, string $docRef[, string $itemRef = 'item' ]) : array{0: string[], 1: string}
It is the query-side counterpart of stripArrayExpansion(): where the
search links and the hierarchical ?filter= builder flatten the
Operator::ARRAY_EXPANSION marker into a dotted path, an aggregation has
to unwind it — an array element cannot be aggregated in place, it must be
iterated. 'offers[*].tiers[*].amount' becomes:
FOR item IN doc.offers
FOR item2 IN item.tiers
… item2.amount
The path is split on the marker, every segment but the last opening one hop
relative to the previous item reference, and the last segment being the
projected leaf — empty for a bare tags[*], which projects the element
itself. Each item reference is <itemRef>, then <itemRef>2, <itemRef>3 …
(there is no <itemRef>1).
Every segment is validated by assertAttributeName() — the whole path
never is, since it carries the markers — so a malformed path fails loud
instead of reaching AQL. A doubled marker (a[*][*]) yields an empty
intermediate container and is rejected on that ground.
The helper deliberately stops at the hops: the root FOR, the shared FILTER
and the aggregation tail belong to the caller, and diverge between consumers
(BoundsQueryTrait collects
MIN/MAX/count, FacetCountsQueryTrait
counts buckets).
Parameters
- $property : string
-
The
[*]-bearing attribute path. - $docRef : string
-
The document reference the first hop starts from.
- $itemRef : string = 'item'
-
The base name of the item variables (default
item).
Tags
Return values
array{0: string[], 1: string} —A [ fors , value ] pair: the FOR hops in
order, and the reference to project (the leaf, or the innermost item
when the path ends on a marker).