AggUnique
AggUnique
returns an aggregator that computes:
- the single unique value contained in each specified column,
- a customizable value, if there are no values present,
- or a customizable value, if there is more than one value present.
Syntax
AggUnique(includeNulls, nonUniqueSentinel, pairs...)
AggUnique(includeNulls, pairs...)
AggUnique(pairs...)
Parameters
Parameter | Type | Description |
---|---|---|
includeNulls | boolean | When set to |
nonUniqueSentinel | UnionObject | The value to output for non-unique groups. The default value is |
pairs | String... | The input/output column names to compute uniqueness for.
|
If an aggregation does not rename the resulting column, the aggregation column will appear in the output table, not the input column. If multiple aggregations on the same column do not rename the resulting columns, an error will result, because the aggregations are trying to create multiple columns with the same name. For example, in table.aggBy([agg.AggSum(“X”), agg.AggAvg(“X”)])
, both the sum and the average aggregators produce column X
, which results in an error.
Returns
An aggregator that computes the single unique value, within an aggregation group, for each input column. If there are no unique values or if there are multiple values, the aggregator returns a specified value.
Examples
In the following example, AggUnique
is used to find and return only the unique values of column X
.
import static io.deephaven.api.agg.Aggregation.AggUnique
source = newTable(
stringCol("X", "A", "A", "B", "B", "B", "C", "C", "D"),
stringCol("Y", "Q", "Q", "R", "R", null, "S", "T", null)
)
result = source.aggBy([AggUnique("Y")], "X")
- source
- result
In the following example, AggUnique
is used to find and return only the unique values of column X
. Nulls are included.
import static io.deephaven.api.agg.Aggregation.AggUnique
source = newTable(
stringCol("X", "A", "A", "B", "B", "B", "C", "C", "D"),
stringCol("Y", "Q", "Q", "R", "R", null, "S", "T", null)
)
result = source.aggBy([AggUnique(true, "Y")], "X")
- source
- result