ARB

ARB selects an arbitrary but consistent value from the set of values in a field.

The syntax of the ARB function is:
ARB(<attribute>)
where attribute is a single-assign attribute or a set (multi-assign attribute).
ARB works as follows:
  • For a single-assign attribute, ARB first discards all NULL values and then selects an arbitrary but consistent value from the remaining non-NULL values. If the attribute has no non-NULL values, then NULL is returned.
  • For a multi-assign attribute, ARB looks at all of the rows in the group (including those with empty sets) and selects the set value from one of the rows. In other words, empty sets and non-empty sets are treated equally. This means that because the selection is arbitrary, the returned set value could be an empty set. The ARB return type is the same as its argument type: if attribute x is an mdex:long-set, then so is ARB(x). If the attribute has no non-NULL values, then the empty set is returned.

ARB examples

Single-assign Example: Price is a single-assign attribute:
RETURN results AS
SELECT ARB(Price) AS prices
FROM WineState
GROUP BY WineType
ORDER BY WineType
The result for this example is:
WineType           prices
--------------------------
| Blanc de Noirs | 16.99 |
| Bordeaux:      | 21.99 |
| Brut           | 22.99 |
| Chardonnay:    | 17.95 |
| Merlot:        | 25.99 |
| Pinot Noir:    | 14.99 |
| Red:           | 9.99  |
| White:         | 20.99 |
| Zinfandel:     |       |
--------------------------
Some of the interesting result values from this data set are:
  • There are three Bordeaux records: one has a Price assignment of 21.99 and the other two have no Price assignments. Therefore, for the Bordeaux value, ARB discarded the two NULL values and returned the 21.99 value.
  • There is one Zinfandel record and it does not have a Price assignment. Therefore, a NULL value is returned.
Multi-assign Example: Body is a multi-assign attribute:
RETURN results AS
SELECT ARB(Body) AS bodies
FROM WineState
GROUP BY WineType
ORDER BY WineType
The result for this example is:
WineType             bodies
----------------------------------------
| Blanc de Noirs | { Firm, Robust }    |
| Bordeaux:      | { Silky, Tannins }  |
| Brut           | { Robust }          |
| Chardonnay:    | { }                 |
| Merlot:        | { }                 |
| Pinot Noir:    | { Supple }          |
| Red:           | { Silky, Tannins }  |
| White:         | { }                 |
| Zinfandel:     | { Robust, Tannins } |
----------------------------------------
Some interesting results from this attribute are:
  • All nine Red records have at least one Body assignment. The returned value for Red is the {Silky, Tannins} set, but, because it is arbitrary, the value could have been any of the other eight sets.
  • Two of the White records have Body assignments (and therefore have non-empty sets) while the other two records have no Body assignments (and therefore have empty sets). One of the White empty sets was returned as the arbitrary value, but it just as well could have been one of the non-empty sets.
  • Neither of the two Chardonnay records have Body assignments, and therefore the empty set was returned for this group.