Skip to content

Commit f944221

Browse files
committed
unique aggregate in handbook and reference
1 parent 0f70da2 commit f944221

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

docs/language/ql-handbook/expressions.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,21 @@ The following aggregates are available in QL:
279279
evaluates to the empty set (instead of defaulting to ``0`` or the empty string).
280280
This is useful if you're only interested in results where the aggregation body is non-trivial.
281281

282+
.. index: unique
283+
284+
- ``unique``: The value of this aggregate depends on how many different values ``<expression>`` can have,
285+
within the context of a fixed set of assignments to outside variables.
286+
If the value is uniquely determined, then the aggregate gives that value. Otherwise, it has no value.
287+
288+
For example, the following aggregation yields the positive integers ``1``, ``2``, ``3``, ``4``, ``5``.
289+
For negative integers ``x``, the expressions ``x`` and ``x.abs()`` have different values and hence the
290+
value for ``y`` in the aggregate expression is not uniquely determined. ::
291+
292+
from int x
293+
where x in [-5 .. 5] and x != 0
294+
select unique(int y | y = x and y = x.abs() | y)
295+
296+
The ``unique`` aggregate is supported from release 2.1.0 of the CodeQL CLI, and release 1.24 of LGTM Enterprise.
282297

283298
Evaluation of aggregates
284299
========================

docs/language/ql-spec/language.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,8 @@ The complete grammar for QL is as follows:
19601960

19611961
aggregation ::= aggid ("[" expr "]")? "(" (var_decls)? ("|" (formula)? ("|" as_exprs ("order" "by" aggorderbys)?)?)? ")"
19621962
| aggid ("[" expr "]")? "(" as_exprs ("order" "by" aggorderbys)? ")"
1963-
1963+
| "unique" "(" var_decls "|" (formula)? ("|" as_exprs)? ")"
1964+
19641965
aggid ::= "avg" | "concat" | "count" | "max" | "min" | "rank" | "strictconcat" | "strictcount" | "strictsum" | "sum"
19651966

19661967
aggorderbys ::= aggorderby ("," aggorderby)*

0 commit comments

Comments
 (0)