Skip to content

Commit 5aa74f2

Browse files
authored
Merge pull request #5629 from influxdata/fix/flux_cardinality_description
fix: clarify behaviour of `influxdb.cardinality()`
2 parents daf4e56 + 2a66e15 commit 5aa74f2

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

content/flux/v0/stdlib/influxdata/influxdb/cardinality.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: influxdb.cardinality() function
33
description: >
4-
`influxdb.cardinality()` returns the series cardinality of data stored in InfluxDB.
4+
`influxdb.cardinality()` returns the series cardinality of data retrieved from InfluxDB.
55
menu:
66
flux_v0_ref:
77
name: influxdb.cardinality
@@ -28,9 +28,16 @@ Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md
2828
2929
------------------------------------------------------------------------------->
3030

31-
`influxdb.cardinality()` returns the series cardinality of data stored in InfluxDB.
31+
`influxdb.cardinality()` returns the series cardinality of data retrieved from InfluxDB.
3232

3333

34+
{{% note %}}
35+
Although this function is similar to InfluxQL's [`SHOW SERIES CARDINALITY`](/influxdb/v1/query_language/spec/#show-series-cardinality),
36+
it works in a slightly different manner.
37+
38+
`influxdb.cardinality()` is time bounded and reports the cardinality of data that matches the conditions passed into it rather than that of the bucket as a whole.
39+
{{% /note %}}
40+
3441

3542
##### Function type signature
3643

@@ -107,6 +114,12 @@ The cardinality calculation excludes points that match the specified start time.
107114
Use a relative duration or absolute time. For example, `-1h` or `2019-08-28T22:00:00Z`.
108115
Durations are relative to `now()`. Default is `now()`.
109116

117+
{{% note %}}
118+
The default value is `now()`, so any points that have been written into the future will
119+
not be counted unless a future `stop` date is provided.
120+
{{% /note %}}
121+
122+
110123
### predicate
111124

112125
Predicate function that filters records.
@@ -120,15 +133,17 @@ Default is `(r) => true`.
120133
- [Query series cardinality in a bucket](#query-series-cardinality-in-a-bucket)
121134
- [Query series cardinality in a measurement//](#query-series-cardinality-in-a-measurement)
122135
- [Query series cardinality for a specific tag](#query-series-cardinality-for-a-specific-tag)
136+
- [Query series cardinality of Data Written In the Last 4 Hours](#query-series-cardinality-of-data-written-in-the-last-4-hours)
123137

124138
### Query series cardinality in a bucket
125139

126140
```js
127141
import "influxdata/influxdb"
128142

129-
influxdb.cardinality(bucket: "example-bucket", start: -1y)
143+
influxdb.cardinality(bucket: "example-bucket", start: time(v: 1))
130144

131145
```
146+
Note: if points have been written into the future, you will need to add an appropriate `stop` date
132147

133148

134149
### Query series cardinality in a measurement//
@@ -138,7 +153,7 @@ import "influxdata/influxdb"
138153

139154
influxdb.cardinality(
140155
bucket: "example-bucket",
141-
start: -1y,
156+
start: time(v: 1),
142157
predicate: (r) => r._measurement == "example-measurement",
143158
)
144159

@@ -150,7 +165,16 @@ influxdb.cardinality(
150165
```js
151166
import "influxdata/influxdb"
152167

153-
influxdb.cardinality(bucket: "example-bucket", start: -1y, predicate: (r) => r.exampleTag == "foo")
168+
influxdb.cardinality(bucket: "example-bucket", start: time(v: 1), predicate: (r) => r.exampleTag == "foo")
169+
170+
```
171+
172+
173+
### Query Cardinality of Data Written In the Last 4 hours
174+
```js
175+
import "influxdata/influxdb"
176+
177+
influxdb.cardinality(bucket: "example-bucket", start: -4h)
154178

155179
```
156180

content/influxdb/v2/reference/faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ Each InfluxDB Cloud organization has a series cardinality limit to prevent
10881088
runaway cardinality. For information about adjusting cardinality limits, see
10891089
[How do I increase my organization’s rate limits and quotas?](#how-do-i-increase-my-organizations-rate-limits-and-quotas).
10901090
1091-
{{% /oss-only %}}
1091+
{{% /cloud-only %}}
10921092
10931093
Use [`influxdb.cardinality()`](/flux/v0/stdlib/influxdata/influxdb/cardinality/) in Flux
10941094
or [`SHOW SERIES CARDINALITY`](/influxdb/v1/query_language/spec/#show-series-cardinality)

0 commit comments

Comments
 (0)