Skip to content

Commit d814a99

Browse files
Merge pull request #21320 from newrelic/revert-21143-revert-20447-precission-parameter-for-uniqueCount-function
feat(precision argument): Adding the precision argument to the UniqueCount function"
2 parents 6c479c1 + f2bc140 commit d814a99

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/content/docs/nrql/nrql-syntax-clauses-functions.mdx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,13 +2115,31 @@ SELECT histogram(duration, 10, 20) FROM PageView SINCE 1 week ago
21152115
<Collapser
21162116
className="freq-link"
21172117
id="func-uniqueCount"
2118-
title={<InlineCode>uniqueCount(attribute)</InlineCode>}
2118+
title={<InlineCode>uniqueCount(attribute, [, attribute [, ...]] [, precision: number])</InlineCode>}
21192119
>
2120-
Use the `uniqueCount()` function to return the number of unique values recorded for an attribute over the time range specified.
21212120

2122-
<Callout variant="tip">
2123-
To optimize query performance, this function returns approximate results for queries that inspect 256 or more unique values.
2124-
</Callout>
2121+
Use the `uniqueCount()` function to get the number of unique values recorded for an attribute over a specified time range. To count the unique combinations of multiple attribute values, specify those attributes with the function. You can include up to 32 attributes. This function provides an exact result for up to 256 unique values when you call it without the `precision` argument. For more than 256 unique values, the result is approximate. You can specify a `precision` value within the range of 256 to 50,000 to increase the threshold for exact results. When unique values exceed the set threshold, the function uses the [HyperLogLog probabilistic data structure](https://algo.inria.fr/flajolet/Publications/FlFuGaMe07.pdf) to provide an approximate result.
2122+
2123+
Use the `uniqueCount()` function by specifying the attributes and optionally set the precision argument as follows:
2124+
2125+
```sql
2126+
uniqueCount(attribute, [, attribute [, ...]] [, precision: number])
2127+
```
2128+
* **Attribute(s)**: Specify an attribute for which you want to count unique values, or specify multiple attributes to count unique combinations of values. You can specify up to 32 attributes.
2129+
* **Precision**: Specify a nuber that sets the threshold for exact results. You can set a value up to 50,000.
2130+
2131+
Query example without a `precision` argument:
2132+
2133+
```sql
2134+
SELECT uniqueCount(accountId) FROM Transaction SINCE 1 day ago
2135+
```
2136+
2137+
Query example with a `precision` argument:
2138+
2139+
```sql
2140+
SELECT uniqueCount(foo, bar, baz, precision: 1000) FROM Transaction SINCE 1 day ago
2141+
```
2142+
21252143
</Collapser>
21262144

21272145
<Collapser

0 commit comments

Comments
 (0)