unique

unique — aggregate function to return a list of the specified number of unique items in the aggregate window.

SYNOPSIS

unique (expr, int numuniq)

DESCRIPTION

This function takes the name of a column in the incoming data (or a StreamBase expression that contains a column name), plus an integer to specify the number of unique results desired. The function returns a list containing the numuniq number of unique column values, whose data type is the same as the queried column.

The unique() function maintains an exact list of unique values until numuniq is reached, and does not report changes as the number of values added exceeds numuniq. If a value in the reported unique list is removed, it is replaced by some other unique value, if one exists. If there are more than numuniq values, there is no guarantee which numuniq values are reported.

You can use unique() in SNAPSHOT or SNAPSHOT_AND_CONTINUOUS queries where the list return type is handled normally. However, when using unique() as part of an author-time aggregation, you must wrap the unique() function in joinlist() to convert the returned list to a formatted string.

EXAMPLE

This example shows how to use dynamic aggregation to find the number of unique values in a column. In the Hello LiveView sample, create a query that finds the number of unique alerts in the LVAlerts table, up to five. Follow these steps:

  1. In LiveView Desktop connected to a server running the Hello LiveView sample, select the LVAlerts table from the Tables pane of the LiveView Tables view.

  2. In the Select field, enter:

    unique(Severity, 5) as SeverityList
    
  3. Make sure the Query field is empty.

  4. Click Open Query.

The query results open in a grid view. LiveView Server continously recalculates number of alerts whenever the rows returned by the query predicate change.

SEE ALSO

This LiveView aggregate function is based on the unique aggregate function in the StreamBase expression language.

See the related LiveView aggregate function joinlist().