influxdata / influxdata/influxdb
Incorrect integral calculations for short activities
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 31.7k
- Forks
- 3.7k
- Avg merge
- 13h 37m
- Merged PRs (30d)
- 8
Description
I have a value series consisting of 1s and 0s, representing the on/off state of a device. I'd like to calculate the integral of this series for a specified time range, but it gives me incorrect results, no matter if I use the integral() function by itself or within aggregateWindow().
I'll give one nice example but I can reproduce it with almost all kinds of similar value series.
Steps to reproduce:
List the minimal actions needed to reproduce the behaviour.
- The input data from my base query looks like this:
(There is a standard sampling every minute, reflecting the current state, but if the state changes in between, additional values are added.)
| _time | _value |
|---|---|
| 2025-04-14 20:00:28 GMT+2 | 0 |
| 2025-04-14 20:01:28 GMT+2 | 0 |
| 2025-04-14 20:02:28 GMT+2 | 0 |
| 2025-04-14 20:03:28 GMT+2 | 0 |
| 2025-04-14 20:03:41 GMT+2 | 1 |
| 2025-04-14 20:04:06 GMT+2 | 0 |
| 2025-04-14 20:05:03 GMT+2 | 1 |
| 2025-04-14 20:05:17 GMT+2 | 0 |
| 2025-04-14 20:06:17 GMT+2 | 0 |
| 2025-04-14 20:07:17 GMT+2 | 0 |
| 2025-04-14 20:08:17 GMT+2 | 0 |
| 2025-04-14 20:09:17 GMT+2 | 0 |
| 2025-04-14 20:10:17 GMT+2 | 0 |
| 2025-04-14 20:11:17 GMT+2 | 0 |
| 2025-04-14 20:12:17 GMT+2 | 0 |
| 2025-04-14 20:13:17 GMT+2 | 0 |
| 2025-04-14 20:14:17 GMT+2 | 0 |
| 2025-04-14 20:15:17 GMT+2 | 0 |
| 2025-04-14 20:16:17 GMT+2 | 0 |
| 2025-04-14 20:17:17 GMT+2 | 0 |
| 2025-04-14 20:18:17 GMT+2 | 0 |
| 2025-04-14 20:19:17 GMT+2 | 0 |
| 2025-04-14 20:20:17 GMT+2 | 0 |
| 2025-04-14 20:21:17 GMT+2 | 0 |
| 2025-04-14 20:22:17 GMT+2 | 0 |
| 2025-04-14 20:23:17 GMT+2 | 0 |
| 2025-04-14 20:24:17 GMT+2 | 0 |
| 2025-04-14 20:25:17 GMT+2 | 0 |
| 2025-04-14 20:26:17 GMT+2 | 0 |
| 2025-04-14 20:27:17 GMT+2 | 0 |
| 2025-04-14 20:28:17 GMT+2 | 0 |
| 2025-04-14 20:29:17 GMT+2 | 0 |
| 2025-04-14 20:30:17 GMT+2 | 0 |
| 2025-04-14 20:31:17 GMT+2 | 0 |
| 2025-04-14 20:32:15 GMT+2 | 1 |
| 2025-04-14 20:32:22 GMT+2 | 0 |
| 2025-04-14 20:33:22 GMT+2 | 0 |
| 2025-04-14 20:34:22 GMT+2 | 0 |
| 2025-04-14 20:35:22 GMT+2 | 0 |
| 2025-04-14 20:36:22 GMT+2 | 0 |
| 2025-04-14 20:37:22 GMT+2 | 0 |
| 2025-04-14 20:38:22 GMT+2 | 0 |
| 2025-04-14 20:39:22 GMT+2 | 0 |
- I use either one of the following integral code blocks (no interpolation):
|> aggregateWindow(
every: duration(v: uint(v: v.timeRangeStop) - uint(v: v.timeRangeStart)),
fn: (tables=<-, column) =>
tables
|> sort(columns: ["_time"])
|> integral(unit: 1s)
,
createEmpty: false
)
|> integral(unit: 1s)
Expected behaviour:
If you calculate the integral by just looking at the table, it's 46 seconds (25+14+7).
Actual behaviour:
When using either of the integral codes, I get the same wrong result, 86.96 seconds:
| _time | _value |
|---|---|
| 2025-04-14 20:40:00 GMT+2 | 86.96 |
Environment info:
InfluxDB running in Docker:
| GOSU_VER | 1.16 |
| INFLUX_CLI_VERSION | 2.7.5 |
| INFLUXDB_VERSION | 2.7.11 |
Config:
Default
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the integral() and aggregateWindow() queries from the issue against the supplied 0/1 time series on InfluxDB 2.7.11. Compare the reported 86.96-second result with the expected 46 seconds; the issue does not name implementation files or tests, so locating the relevant integral code and regression coverage will require repository research.
Written by the indexing model from the issue text.
Assessment
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100