Represents multiple results from a single attribute extraction.
MultiResult is an aggregate of results that is returned if the ValueExtractor returns multiple results due to a
reduce operation executed on a hierarchy of values.
It sounds counter-intuitive, but a single extraction may return multiple values when arrays or collections are
involved.
Let's have a look at the following data structure:
class Swap {
Leg legs[2];
}
class Leg {
String currency;
}
The following extraction of the currency attribute
legs[any].currency
results in two currencies for each
Leg. In order to return both values in one result of the extract operation both currencies are returned in a
single MultiResult object where each result contains a name of the currency.
It allows the user to operate on multiple "reduced" values as if they were single-values.
Let's have a look at the following queries:
- leg[1].currency = 'EUR'
- leg[any].currency = 'EUR'
In the first query, the extraction will return just one currency, whereas the extraction in the second query will
return a MultiResult containing two currencies.
During the evaluation of the "=" equals predicate the MultiResult will be "unfolded" and the condition will
evaluated against all currencies from the MultiResult. If there is "any" currency that matches the condition the
whole predicate will be evaluated to "true" and the matching Swap will be returned.
As a result all Swaps will be returned where there's at lease one Leg with EUR currency.
Other examples:
legs -> returns one 'single-value' result -> a collection of values
legs[0] -> returns one 'single result' - a Leg object
legs[0].currency -> returns one 'multi value' result - an array of Legs
legs[any] -> returns a MultiResult - that contains a collection of Leg objects
legs[any].currency -> returns a MultiResult - that contains a collection of String objects