influxdata / influxdata/influxdb

mode function doesn't work properly

Open
#21,070 0 comments 0 reactions 0 assignees View on GitHub
area/2.x area/flux area/queries
Dominant language
Rust
Stars
31.7k
Forks
3.7k
Avg merge
13h 37m
Merged PRs (30d)
8

Description

When we implement, for example, the following task in InfluxDB (not necessarily a task, it also happens using the script builder) the mode function return null or '' when the initial bucket contains the same value in every row.

For example, if a value of "5" has been received throughout the hour every second, when mode is calculated the result should be 5 for that hour, however the function appears to return null or an empty value.

On the contrary, if the received value is not repeated throughout the hour and there are more different values, mode is calculated correctly.

Example task:

`option task = {name: "taskName", cron: "0 * * * *", offset: 10m}`
`option v = {timeRangeStart: -24h, timeRangeStop: now(), windowPeriod: 1h}`

`data = from(bucket: "bucketName")`
`|> range(start: v.timeRangeStart, stop: v.timeRangeStop)`
`|> filter(fn: (r) =>`
`(r._measurement == "filterName"))`

`data`
`|> aggregateWindow(every: v.windowPeriod, fn: mode, createEmpty: false)`
`|> set(key: "keyValue", value: "mode")`
`|> to(bucket: "oneHourBucket", org: "orgName")`

![image](https://user-images.githubusercontent.com/50336098/112494305-3424ef00-8d83-11eb-9b42-2d388524ae69.jpg)

Environment info:

System info: Linux 4.19.104-microsoft-standard x86_64
InfluxDB version: InfluxDB 2.0.4 (git: 4e7a59b) build_date: 2021-02-08T17:47:02Z
Docker Version: 3.2.1 (61626), Engine 20.10.5.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the task or script-builder example with aggregateWindow(every: v.windowPeriod, fn: mode) on a bucket whose values are all 5, then compare it with a bucket containing different values. Done means mode returns 5 for the constant one-hour window instead of null or an empty value, while the existing varying-value behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.